1

I have recently noticed that when I upgraded to Androids API of 30 or higher, my linking functionality has stopped working. It appears the reasoning is due to Android implementing the need to declare package visibility.

So now, when I try to open the default sms messaging app on my android device using Linking.canOpenURL, nothing happens.

I am assuming adding this package name to my AndroidManifest.xml file will fix this. Looking at the example code from the android documentation, we see the following.

<manifest package="com.example.game">
    <queries>
        <package android:name="com.example.store" />
        <package android:name="com.example.services" />
    </queries>
    ...
</manifest>

I want to be able to open the default sms messaging app on ANY android device. How can I grab the package name of the default sms app for ANY device and include it in my manifest file?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
MouseWarrior
  • 391
  • 4
  • 19

1 Answers1

1

You don't need to know what the default messaging app is in order to launch it. All you need it to send this intent:

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_APP_MESSAGING);
    intent.setFlags(Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);

Or if you actually want to start a text message to a specific phone#:

    Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("sms:5551234567"));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);

Obviously, replace "5551234567" with the actual phone number

user496854
  • 6,461
  • 10
  • 47
  • 84
  • So I would use this intent rather than the linking.canOpenURL function? Just a tad confused still... I need to open the sms app as well as pass it the phone number to start texting. – MouseWarrior Sep 06 '22 at 02:08
  • What I posted will just open the default SMS app. If you want to start a new text message, you'll need a different intent. I'm updating my answer... – user496854 Sep 06 '22 at 02:14
  • 1
    Just FYI - I updated the answer again -- the 2nd intent should not have `intent.addCategory()` – user496854 Sep 06 '22 at 02:29
  • Wont be at my computer until tomorrow but I will update answer ASAP – MouseWarrior Sep 06 '22 at 02:32
  • Where is the documentation for Intents? I cannot seem to find them – MouseWarrior Sep 06 '22 at 02:48
  • 1
    Not sure what docs you're referring to, but here's some info on common intents: https://developer.android.com/guide/components/intents-common – user496854 Sep 06 '22 at 02:57
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/247805/discussion-between-guts716-and-user496854). – MouseWarrior Sep 06 '22 at 03:04