This person was generous enough to add his code to his question。但我不能让从何处获取下列变量:向主屏幕添加android启动器快捷方式
res
,app_id
和p
在
BitmapDrawable bd = (BitmapDrawable) (res.get(app_id).activityInfo.loadIcon(p).getCurrent());
这里是他的代码:
Intent shortcutIntent = new Intent();
shortcutIntent.setClassName(ai.packageName, ai.name);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.addCategory(Intent.ACTION_PICK_ACTIVITY);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
BitmapDrawable bd=(BitmapDrawable)(res.get(app_id).activityInfo.loadIcon(p).getCurrent());
Bitmap newbit;
newbit=bd.getBitmap();
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, newbit);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(intent);
此外,是否有任何我必须添加到清单文件?
编辑:
我
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this, R.drawable.launcher_icon));
更换
BitmapDrawable bd=(BitmapDrawable)(res.get(app_id).activityInfo.loadIcon(p).getCurrent());
Bitmap newbit;
newbit=bd.getBitmap();
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, newbit);
,它仍然无法正常工作。这就是为什么我想知道清单文件。
阅读文档调用的函数。这里描述了这些参数的含义。 –
看来你没有努力去自己理解和修改代码 –
@MichaelButscher你知道我的新代码不工作么?清单中是否有要添加的内容? –