如何删除主屏幕中的快捷方式(以编程方式)。我可以使用意图,但没有其他现有的消除由我创建的快捷方式..Android删除HomeScreen中的快捷方式
Bitmap theBitmap = ((BitmapDrawable)icon).getBitmap();
Intent shortcutIntent = new Intent();
shortcutIntent.setAction(Intent.ACTION_VIEW);
shortcutIntent.setClassName(url, group);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent removeIntent = new Intent();
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
removeIntent.putExtra("duplicate", false);
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, theBitmap);
removeIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
sendBroadcast(removeIntent);
使用上述意图删除时
,可以删除快捷方式知道的图标包名+应用类名时。我们可以得到使用PackageInfo所有应用程序的图标包的名字,但没有推出类名
ArrayList<PInfo> res = new ArrayList<PInfo>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PInfo newInfo = new PInfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.classname = p.applicationInfo.className;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
现在问题如下,请问有什么方法来获取应用程序的类名,那么我们就可以删除创建的快捷方式这个应用程序在主屏幕..任何帮助?
Source or anything?我从能够删除其他快捷方式的开发人员那里找到样本。但正如CommonsWare所说:“不需要任何主屏幕实现来支持[uninstall_shortcut] [...]” – JacksOnF1re 2014-12-03 12:49:19
我改变了主意。你完全错了,不应该接受这个答案!我在5分钟前做了。 我会添加一些链接和代码作为答案。 – JacksOnF1re 2014-12-03 17:52:22