Waz*_*_Be 6 icons android shortcut drawable android-intent
下面是我的代码,用于创建所选应用程序的快捷方式.我真的没问题,应用程序工作得很好.
问题是我能够从我的应用程序创建一个带有ressource的快捷方式:
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
Run Code Online (Sandbox Code Playgroud)
但我真的想要一个定制的drawable.(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();
Run Code Online (Sandbox Code Playgroud)
非常感谢任何线索
Waz*_*_Be 28
终于找到了解决方案; 使用Intent.EXTRA_SHORTCUT_ICON_RESOURCE我很愚蠢:
这是正确的代码:
Drawable iconDrawable = (....);
BitmapDrawable bd = (BitmapDrawable) iconDrawable;
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bd.getBitmap());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6033 次 |
| 最近记录: |