Reputation: 531
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
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