Skip to content

Instantly share code, notes, and snippets.

@suau
Created April 7, 2015 11:04
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save suau/705061f8fa0295471829 to your computer and use it in GitHub Desktop.
Save suau/705061f8fa0295471829 to your computer and use it in GitHub Desktop.
share text to android applications except facebook
public static void shareWithoutFacebook(Context context, String text) {
// get available share intents
List<Intent> targets = new ArrayList<>();
Intent template = new Intent(Intent.ACTION_SEND);
template.setType("text/plain");
List<ResolveInfo> resolveInfos = context.getPackageManager().
queryIntentActivities(template, 0);
// remove facebook which has a broken share intent
for (ResolveInfo resolveInfo : resolveInfos) {
String packageName = resolveInfo.activityInfo.packageName;
if (!packageName.equals("com.facebook.katana")) {
Intent target = new Intent(android.content.Intent.ACTION_SEND);
target.setType("text/plain");
target.putExtra(Intent.EXTRA_TEXT, text);
target.setPackage(packageName);
targets.add(target);
}
}
Intent chooser = Intent.createChooser(targets.remove(0), "Chooser Dialog Title");
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, targets.toArray(new Parcelable[]{}));
context.startActivity(chooser);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment