- private void parseApk(String apkPath) {
- PackageManager pm = getPackageManager();
- PackageInfo info = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES);
- if (info != null) {
- ApplicationInfo appInfo = info.applicationInfo;
- appInfo.sourceDir = apkPath;
- appInfo.publicSourceDir = apkPath;
- try {
- addShortCut((String)appInfo.loadLabel(pm), appInfo.loadIcon(pm), apkPath);
- } catch (OutOfMemoryError e) {
- Log.e("ApkIconLoader", e.toString());
- }
- }
- }
- private void addShortCut(String label, Drawable icon, String path) {
- Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
- // 设置属性
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
- // 设置桌面快捷方式的图标
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON, ((BitmapDrawable) icon).getBitmap());
- // 是否允许重复创建
- shortcut.putExtra("duplicate", false);
- // 点击快捷方式的操作
- Intent intent = getInstallIntent(path);
- // 设置启动程序
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
- // 广播通知桌面去创建
- sendBroadcast(shortcut);
- }
- //该片段来自于http://www.codesnippet.cn/detail/0808201614928.html
来源: http://www.codesnippet.cn/detail/0808201614928.html