Customize your ACTION_CHOOSER Intent
For an Android Intent chooser, it is possible to either remove an Intent or add an custom Intent, this is how we do it:
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "http://www.blogspot.com");
List<ResolveInfo> resInfo = this.getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : resInfo) {
String packageName = resolveInfo.activityInfo.packageName;
Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND);
targetedShareIntent.setType("text/plain");
targetedShareIntent.putExtra(Intent.EXTRA_TEXT, "http://www.blogspot.com");
targetedShareIntent.setPackage(packageName);
if (!packageName.equals("com.facebook.katana")) { // Remove Facebook Intent share
targetedShareIntents.add(targetedShareIntent);
}
}
// Add my own activity in the share Intent chooser
Intent i = new Intent(this, NextActivity.class);
targetedShareIntents.add(i);
Intent chooserIntent = Intent.createChooser(
targetedShareIntents.remove(0), "Select app to share");
chooserIntent.putExtra(
Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
Very nice reference from the following posts:
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "http://www.blogspot.com");
List<ResolveInfo> resInfo = this.getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : resInfo) {
String packageName = resolveInfo.activityInfo.packageName;
Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND);
targetedShareIntent.setType("text/plain");
targetedShareIntent.putExtra(Intent.EXTRA_TEXT, "http://www.blogspot.com");
targetedShareIntent.setPackage(packageName);
if (!packageName.equals("com.facebook.katana")) { // Remove Facebook Intent share
targetedShareIntents.add(targetedShareIntent);
}
}
// Add my own activity in the share Intent chooser
Intent i = new Intent(this, NextActivity.class);
targetedShareIntents.add(i);
Intent chooserIntent = Intent.createChooser(
targetedShareIntents.remove(0), "Select app to share");
chooserIntent.putExtra(
Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
Very nice reference from the following posts:
Thanks! This helped me out with the facebook problem. :-)
ReplyDeleteIf I do not want to show some activity in chooser dialog, what should I do?
ReplyDeleteresponse is, "No apps can perform this action".
ReplyDelete@Anonymous When you run this code, Android checks if you have apps that can run your ACTION_SENT intent. So if you do not have any apps like Whats app or Facebook installed on your Android then you know... No apps can perform your action.
ReplyDelete@Correction ACTION_SEND
DeleteImagine asking a six-year-old to sit down and watch an Oscar winner for best picture. No matter if the movie is the best of the year, the six-year-old will not be interested because he is not the right audience. They prefer to see SpongeBob.
ReplyDeletehttps://ppcexpo.com/blog/custom-intent-audiences