我正在使用类似下面展示的代码片段来在主屏幕上添加应用程序快捷方式:
在创建快捷方式时没有任何问题,但是当卸载应用程序时,在主屏幕上的快捷方式仍然存在。当卸载其他应用程序时,它们似乎都会删除相应的主屏幕快捷方式。这就是我试图通过“通过代码创建的快捷方式图标”来实现的。
在Stackoverflow上,有没有Android专家知道卸载应用程序时如何从主屏幕中删除应用程序快捷方式?
我找到了一些相关的线程,但它们没有为我的问题提供解决方案,但请随意查看:
[0] https://developer.android.com/intl/de/resources/samples/ApiDemos/src/com/example/android/apis/app/LauncherShortcuts.html [1] Remove application from launcher programatically in Android [2] How to remove application shortcut from home screen on uninstall automatically?
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.setClassName(this, this.getClass().getName());
shortcutIntent.putExtra(EXTRA_KEY, "ApiDemos Provided This Shortcut");
// Then, set up the container intent (the response to the caller)
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.shortcut_name));
Parcelable iconResource = Intent.ShortcutIconResource.fromContext(
this, R.drawable.app_sample_code);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
// Now, return the result to the launcher
setResult(RESULT_OK, intent);
在创建快捷方式时没有任何问题,但是当卸载应用程序时,在主屏幕上的快捷方式仍然存在。当卸载其他应用程序时,它们似乎都会删除相应的主屏幕快捷方式。这就是我试图通过“通过代码创建的快捷方式图标”来实现的。
在Stackoverflow上,有没有Android专家知道卸载应用程序时如何从主屏幕中删除应用程序快捷方式?
我找到了一些相关的线程,但它们没有为我的问题提供解决方案,但请随意查看:
[0] https://developer.android.com/intl/de/resources/samples/ApiDemos/src/com/example/android/apis/app/LauncherShortcuts.html [1] Remove application from launcher programatically in Android [2] How to remove application shortcut from home screen on uninstall automatically?