简体   繁体   中英

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

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?


在此处输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM