How can I prevent my app from showing specific apps on startActivity()

Viewed 27

When a user clicks a button in my app, it's supposed to launch an SMS app. To to this, I simply fired an intent.

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", "+234000000000", null));
intent.putExtra("sms_body", "Hello!"));
if (intent.resolveActivity(getActivity().getPackageManager()) != null) startActivity(intent);

This works perfectly fine! The only problem is that Facebook Messenger is among the list of apps that show up and I don't want that.

How can I filter this list and remove specific apps like Messenger?


enter image description here

2 Answers

Yes, you can restrict your app to open just android default messaging app.

            Uri uri = Uri.parse("sms:+444498494984");
            Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
            //android sms app package name
            intent.setPackage("com.google.android.apps.messaging");
            intent.putExtra("sms_body", "message to send");
            if (intent.resolveActivity(getPackageManager()) != null)
            {
                startActivity(intent);
            }

It is trying to give the user a choice on their favourite SMS app, Don't forget that Facebook Messenger can also manage SMS now that is why it is showing up as a choice. In my experience, Unless the user selects 'always' it can't be avoided. Imagine if the user has other apps to manage SMS we can't force them to use our preferred messaging app.

Related