Vous trouverez ci-dessous Mon code pour créer un raccourci vers une application sélectionnée. Je n'ai vraiment aucun problème et l'application fonctionne très bien.Création d'un raccourci: comment puis-je travailler avec un dessinable en tant qu'icône?
Le problème est que je suis en mesure de créer un raccourci avec un de ma demande ressource:
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
Mais je voudrais vraiment avec un drawable personnalisé. (Drawable myDrawable = .....)
Comment puis-je faire?
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();
Merci beaucoup pour tout indice
ShortcutIconResource.fromContext (pkgContext, iconID) faire le tric k! http://stackoverflow.com/questions/17339231/create-shortcut-for-thrid-party-app-is-that-possible/17561676#17561676 – thecr0w