2 gy1422871384 gy1422871384 于 2013.10.12 12:00 提问

如何让launcher自动为新安装apk创建快捷方式到桌面

这是关于launcher的开发,目的是launcher 自动给新安装的app创建快捷方式不是 app给自己创建快捷方式到workspace。求指点,谢谢!

2个回答

gy1422871384
gy1422871384   2013.10.23 16: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);

pingchuanyang
pingchuanyang   2013.10.13 11:02
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!