Aquí va su solución. Si desea excluir su aplicación se puede cambiar "packageNameToExclude" con ctx.getPackageName()
public static Intent shareExludingApp(Context ctx, String packageNameToExclude, String imagePath, String text) {
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/*");
List<ResolveInfo> resInfo = ctx.getPackageManager().queryIntentActivities(createShareIntent(text,new File(imagePath)), 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo info : resInfo) {
Intent targetedShare = createShareIntent(text,new File(imagePath));
if (!info.activityInfo.packageName.equalsIgnoreCase(packageNameToExclude)) {
targetedShare.setPackage(info.activityInfo.packageName);
targetedShareIntents.add(targetedShare);
}
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0),
"Select app to share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
targetedShareIntents.toArray(new Parcelable[] {}));
return chooserIntent;
}
return null;
}
private static Intent createShareIntent(String text, File file) {
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/*");
if (text != null) {
share.putExtra(Intent.EXTRA_TEXT, text);
}
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
return share;
}
esto hay algo construido en el que se puede alimentar a mi lista filtrada vuelta en, para crear el cuadro de diálogo Compartir, o tengo que crear mi propio cuadro de diálogo usando la lista? Si es el último, ¿cómo aparece el ícono de la aplicación en un diálogo? Gracias. –
cottonBallPaws
@littleFluffyKitty: usaría su propio cuadro de diálogo (por ejemplo, 'AlertDialog.Builder' y' setAdapter() '). 'PackageManager' puede darle los iconos. Ver http://github.com/commonsguy/cw-advandroid/tree/master/Introspection/Launchalot/ – CommonsWare
gracias, eso es realmente útil. ¿Tiene alguna sugerencia que sea la mejor manera de comparar/filtrar la lista devuelta por queryIntentActivities() contra mi aplicación? Estaba pensando en usar el nombre del paquete, pero ¿hay una mejor comparación? – cottonBallPaws