这是关于launcher的开发,目的是launcher 自动给新安装的app创建快捷方式 , 不是 app给自己创建快捷方式到workspace。求指点,谢谢!
2条回答 默认 最新
- gy1422871384 2013-10-23 08:42关注
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, info.title.toString());
Intent respondIntent = info.intent;
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, respondIntent);
Context pkgContext = null;
int iconIdentifier = 0;
PackageManager manager = mLauncher.getPackageManager();
System.out.println("manager="+manager);
android.content.pm.ApplicationInfo appInfo;
try {
appInfo = manager.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
iconIdentifier = appInfo.icon;
} catch (NameNotFoundException e1) {
e1.printStackTrace();
}
try {
pkgContext = mLauncher.createPackageContext(packageName,Context.CONTEXT_IGNORE_SECURITY
| Context.CONTEXT_INCLUDE_CODE);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
if (pkgContext != null) {
ShortcutIconResource iconRes = Intent.ShortcutIconResource
.fromContext(pkgContext, iconIdentifier);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,iconRes);
}
mLauncher.sendBroadcast(shortcut);本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 ubuntu子系统密码忘记
- ¥15 保护模式-系统加载-段寄存器
- ¥15 电脑桌面设定一个区域禁止鼠标操作
- ¥15 求NPF226060磁芯的详细资料