Disable custom intent chooser

This commit is contained in:
Dominik Schürmann 2014-08-21 14:07:37 +02:00
parent acff54d7d7
commit b7de91ad51

View File

@ -309,59 +309,60 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn
String title = isContentMessage() ? getString(R.string.title_share_message) String title = isContentMessage() ? getString(R.string.title_share_message)
: getString(R.string.title_share_file); : getString(R.string.title_share_file);
// fallback on Android 2.3, otherwise we would get weird results // Disabled, produced an empty list on Sony (model will be inserted here)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // // fallback on Android 2.3, otherwise we would get weird results
return Intent.createChooser(prototype, title); // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
} // return Intent.createChooser(prototype, title);
// }
// prevent recursion aka Inception :P //
String[] blacklist = new String[]{Constants.PACKAGE_NAME + ".ui.EncryptActivity"}; // // prevent recursion aka Inception :P
// String[] blacklist = new String[]{Constants.PACKAGE_NAME + ".ui.EncryptActivity"};
List<LabeledIntent> targetedShareIntents = new ArrayList<LabeledIntent>(); //
// List<LabeledIntent> targetedShareIntents = new ArrayList<LabeledIntent>();
List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(prototype, 0); //
List<ResolveInfo> resInfoListFiltered = new ArrayList<ResolveInfo>(); // List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(prototype, 0);
if (!resInfoList.isEmpty()) { // List<ResolveInfo> resInfoListFiltered = new ArrayList<ResolveInfo>();
for (ResolveInfo resolveInfo : resInfoList) { // if (!resInfoList.isEmpty()) {
// do not add blacklisted ones // for (ResolveInfo resolveInfo : resInfoList) {
if (resolveInfo.activityInfo == null || Arrays.asList(blacklist).contains(resolveInfo.activityInfo.name)) // // do not add blacklisted ones
continue; // if (resolveInfo.activityInfo == null || Arrays.asList(blacklist).contains(resolveInfo.activityInfo.name))
// continue;
resInfoListFiltered.add(resolveInfo); //
} // resInfoListFiltered.add(resolveInfo);
// }
if (!resInfoListFiltered.isEmpty()) { //
// sorting for nice readability // if (!resInfoListFiltered.isEmpty()) {
Collections.sort(resInfoListFiltered, new Comparator<ResolveInfo>() { // // sorting for nice readability
@Override // Collections.sort(resInfoListFiltered, new Comparator<ResolveInfo>() {
public int compare(ResolveInfo first, ResolveInfo second) { // @Override
String firstName = first.loadLabel(getPackageManager()).toString(); // public int compare(ResolveInfo first, ResolveInfo second) {
String secondName = second.loadLabel(getPackageManager()).toString(); // String firstName = first.loadLabel(getPackageManager()).toString();
return firstName.compareToIgnoreCase(secondName); // String secondName = second.loadLabel(getPackageManager()).toString();
} // return firstName.compareToIgnoreCase(secondName);
}); // }
// });
// create the custom intent list //
for (ResolveInfo resolveInfo : resInfoListFiltered) { // // create the custom intent list
Intent targetedShareIntent = (Intent) prototype.clone(); // for (ResolveInfo resolveInfo : resInfoListFiltered) {
targetedShareIntent.setPackage(resolveInfo.activityInfo.packageName); // Intent targetedShareIntent = (Intent) prototype.clone();
targetedShareIntent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name); // targetedShareIntent.setPackage(resolveInfo.activityInfo.packageName);
// targetedShareIntent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
LabeledIntent lIntent = new LabeledIntent(targetedShareIntent, //
resolveInfo.activityInfo.packageName, // LabeledIntent lIntent = new LabeledIntent(targetedShareIntent,
resolveInfo.loadLabel(getPackageManager()), // resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.icon); // resolveInfo.loadLabel(getPackageManager()),
targetedShareIntents.add(lIntent); // resolveInfo.activityInfo.icon);
} // targetedShareIntents.add(lIntent);
// }
// Create chooser with only one Intent in it //
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(targetedShareIntents.size() - 1), title); // // Create chooser with only one Intent in it
// append all other Intents // Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(targetedShareIntents.size() - 1), title);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{})); // // append all other Intents
return chooserIntent; // chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
} // return chooserIntent;
// }
} //
// }
// fallback to Android's default chooser // fallback to Android's default chooser
return Intent.createChooser(prototype, title); return Intent.createChooser(prototype, title);