-
-
Save tajchert/73422616624090851fa5 to your computer and use it in GitHub Desktop.
Due to Facebook not handling any text in share intent (ACTION_SEND), and not trying to fix it (it is a "feature"), lets remove it from share dialog - as otherwise it results in broken user experience and most likely users will blame us not the Facebook. Bug on Facebook issue tracker https://developers.facebook.com/bugs/332619626816423
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage: | |
// your share intent | |
Intent intent = new Intent(Intent.ACTION_SEND); | |
intent.setType("text/plain"); | |
intent.putExtra(Intent.EXTRA_TEXT, "some text"); | |
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "a subject"); | |
// invoke custom chooser that contains all apps just without Facebook | |
startActivity(Tools.customChooserIntentNoFb(intent, "Share using", context)); | |
// Method: | |
public static Intent customChooserIntentNoFb(Intent target, String shareTitle, Context context) { | |
// blacklist | |
String[] blacklist = new String[]{"com.facebook.katana"}; | |
List<Intent> targetedShareIntents = new ArrayList<Intent>(); | |
List<HashMap<String, String>> intentMetaInfo = new ArrayList<HashMap<String, String>>(); | |
Intent chooserIntent; | |
Intent dummy = new Intent(target.getAction()); | |
dummy.setType(target.getType()); | |
List<ResolveInfo> resInfo = context.getPackageManager().queryIntentActivities(dummy, 0); | |
if (!resInfo.isEmpty()) { | |
for (ResolveInfo resolveInfo : resInfo) { | |
if (resolveInfo.activityInfo == null || Arrays.asList(blacklist).contains(resolveInfo.activityInfo.packageName)) | |
continue; | |
HashMap<String, String> info = new HashMap<String, String>(); | |
info.put("packageName", resolveInfo.activityInfo.packageName); | |
info.put("className", resolveInfo.activityInfo.name); | |
info.put("simpleName", String.valueOf(resolveInfo.activityInfo.loadLabel(context.getPackageManager()))); | |
intentMetaInfo.add(info); | |
} | |
if (!intentMetaInfo.isEmpty()) { | |
// sorting for nice readability | |
Collections.sort(intentMetaInfo, new Comparator<HashMap<String, String>>() { | |
@Override | |
public int compare(HashMap<String, String> map, HashMap<String, String> map2) { | |
return map.get("simpleName").compareTo(map2.get("simpleName")); | |
} | |
}); | |
// create the custom intent list | |
for (HashMap<String, String> metaInfo : intentMetaInfo) { | |
Intent targetedShareIntent = (Intent) target.clone(); | |
targetedShareIntent.setPackage(metaInfo.get("packageName")); | |
targetedShareIntent.setClassName(metaInfo.get("packageName"), metaInfo.get("className")); | |
targetedShareIntents.add(targetedShareIntent); | |
} | |
chooserIntent = Intent.createChooser(targetedShareIntents.remove(targetedShareIntents.size() - 1), shareTitle); | |
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{})); | |
return chooserIntent; | |
} | |
} | |
return Intent.createChooser(target, shareTitle); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
perfect..thanks