Di seguito è riportato il mio codice per creare un collegamento a un'applicazione selezionata. Non ho davvero alcun problema e l'applicazione funziona abbastanza bene.Creazione di una scorciatoia: come posso lavorare con un drawable come icona?
Il problema è che sono in grado di creare un collegamento con un ressource dalla mia applicazione:
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
Ma mi piacerebbe davvero con un disegnabile personalizzato. (Drawable myDrawable = .....)
Come posso fare?
ResolveInfo launchable=adapter.getItem(position);
final Intent shortcutIntent = new Intent();
ActivityInfo activity=launchable.activityInfo;
ComponentName name=new ComponentName(activity.applicationInfo.packageName,activity.name);
shortcutIntent.setComponent(name);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
final Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
// Sets the custom shortcut's title
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, launchable.loadLabel(pm));
// Set the custom shortcut icon
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
// add the shortcut
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
finish();
Grazie molto per qualsiasi indizio
ShortcutIconResource.fromContext (pkgContext, iconId) fare il tric K! http://stackoverflow.com/questions/17339231/create-shortcut-for-thrid-party-app-is-that-possible/17561676#17561676 – thecr0w