1

My Android App uses an intent call with a couple of parameters to the default SMS App on the device thus;

    public void RequestSmsCode(String number, String message) {
        Intent intent = new Intent(Intent.ACTION_SENDTO);
        intent.setData(Uri.parse("smsto:" + number));  // This ensures only SMS apps respond
        intent.putExtra("sms_body", message);
        if (intent.resolveActivity(getPackageManager()) != null) {
            try{
                startActivity(intent);
            } catch (Exception ex) {
                DialogResult("SMS App not found", "Please use SMS App to request code");
                ex.printStackTrace();
            }
        }
    }

This has worked absolutely fine up to and including Android 10, but on Android 11 nothing happens..!

My App is not an SMS sending App, this intent is only used for a registration procedure in lieu of building in SMS functionality, which isn't needed and complicates App distribution.

Something has changed in Android v11 and I haven't been able to spot it so far.

Question: Is there a quick way to get this working on all versions again..?

Well yes, reason being "Package visibility in Android 11". Remove...

if (intent.resolveActivity(getPackageManager()) != null)

Seems a bit brutal though, makes me wonder why it was there in the first place, given there's no else, other than it being shown in multiple Android examples. Other ideas not tested yet...

This is quite good 'cos theoretically it fires up any default sms messaging app;

<manifest package="com.example.stuff">
...
<queries>
    <intent>
        <action android:name="android.intent.action.SENDTO" />
        <data android:scheme="smsto"/>
    </intent>
</queries>
...
</manifest>

This one would only fire Google's messaging app, you could add others.

<manifest package="com.example.stuff">
...
<queries>
    <package android:name="com.google.android.apps.messaging" />
</queries>
...
</manifest>

rangi
  • 361
  • 2
  • 4
  • 21

0 Answers0