我正在从我的设备上创建已安装的应用程序的快捷方式。我想要在我的应用程序中获取所有应用程序的启动器图标。但因为我不知道该代码得到它,我用这一个的平均时间(这是我正在开发当前应用程序的图标):在Android中获取安装的快捷方式的应用程序图标
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.ic_launcher));
你可能会请帮助我从设备中获取已安装应用程序的启动器图标?
这里是我的代码安装快捷方式。
ActivityInfo ai = res.get(app_id).activityInfo;
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.setClassName(ai.packageName, ai.name);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
intent.putExtra("duplicate", false);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.ic_launcher));
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(intent);
获得误差在i.addView(i)中。它说,方法addView(ImageView)对于ImageView类型是未定义的。 – androidBoomer
也在行i =(ImageView)i.getChildAt(0),它表示,方法getChildAt(int)未定义类型ImageView – androidBoomer
@androidBoomer:我的坏,抱歉!我在我的答案中更新了代码。 – VikramV