【发布时间】:2011-03-18 22:53:59
【问题描述】:
以下是我创建所选应用程序快捷方式的代码。我真的没有问题,应用程序运行良好。
问题是我可以使用我的应用程序中的资源创建快捷方式:
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
但我真的很想要一个自定义的可绘制对象。 (Drawable myDrawable=.....)
我该怎么办?
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();
非常感谢任何线索
【问题讨论】:
-
ShortcutIconResource.fromContext(pkgContext, iconId) 成功了! stackoverflow.com/questions/17339231/…
标签: android icons android-intent shortcut drawable