kruz05
kruz05

Reputation: 531

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?

Upvotes: 7

Views: 4215

Answers (2)

xuxu
xuxu

Reputation: 6492

if (intent.resolveActivity(pm) == null) {
    // activity not found
}

Upvotes: -1

Raghav Sood
Raghav Sood

Reputation: 82583

    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.
    }

Upvotes: 24

Related Questions