Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect android apps that can handle requested Intent action?

I want to share text message trough twitter, facebook or in other ways that available on device. I wrote next code:

    Intent share = new Intent(Intent.ACTION_SEND);
    share.putExtra(Intent.EXTRA_TEXT, "Here's some text for Twitter.");
    startActivity(Intent.createChooser(share, "Share this via"));       

But if no apps that can hadle this action, the "no such apps" dialog appears on screen. I want to detect these apps and disable this function if there is no handlers found. How I can do it?

like image 964
kruz05 Avatar asked Oct 18 '12 18:10

kruz05


People also ask

How can you tell which activity Intent is coming?

ActivityCompat. startActivityForResult(this, new Intent(this, MyActivity. class), 0, null);

How do you retrieve data which is send from an Intent?

This Intent object can be retrieved via the getIntent() method. The component which receives the intent can use the getIntent(). getExtras() method call to get the extra data.

What triggers an Intent in Android?

Android Intent is the message that is passed between components such as activities, content providers, broadcast receivers, services etc. It is generally used with startActivity() method to invoke activity, broadcast receivers etc. The dictionary meaning of intent is intention or purpose.


1 Answers

    Intent intent = new Intent...
    PackageManager manager = mContext.getPackageManager();
    List<ResolveInfo> list = manager.queryIntentActivities(intent, 0);

    if (list != null && list.size() > 0) {
        //You have at least one activity to handle the intent
    } else {
        //No activity to handle the intent.
    }
like image 177
Raghav Sood Avatar answered Sep 24 '22 07:09

Raghav Sood