Unten ist Mein Code, um eine Verknüpfung zu einer ausgewählten Anwendung zu erstellen. Ich habe wirklich kein Problem und die Anwendung funktioniert ganz gut.Erstellen einer Verknüpfung: Wie kann ich mit einem Zeichen als Symbol arbeiten?
Das Problem ist, dass ich in der Lage bin eine Verknüpfung mit einer Ressource von meiner Anwendung zu erstellen:
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
Aber ich würde mit einem benutzerdefinierten ziehbar wirklich gut gefällt. (Drawable myDrawable = .....)
Wie kann ich tun?
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();
Vielen viel für jeden Hinweis
ShortcutIconResource.fromContext (pkgContext, iconID) tun, um die tric helfen k! http://stackoverflow.com/questions/17339231/create-shortcut-for-thrip-party-app-is-that-possible/17561676#17561676 – thecr0w