我正在尝试从我的应用已添加的主屏幕中删除快捷方式。我已尝试过这些链接中的方法,但我无法弄清楚如何使他们的解决方案适应我的代码。我没有root设备,所以我找不到URI。
Trying to UNINSTALL_SHORTCUT but shortcut won't go away
Android: Remove app shortcut from home screen
这是我创建快捷方式的地方:
protected void ShortcutCreatorActivity(String number, String message, String name) {
Intent shortcutIntent = new Intent(getApplicationContext(), ShortCutActivity.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.putExtra("number", number);
shortcutIntent.putExtra("message", message);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
}
这是我的清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abezukor.autosms" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.SEND_SMS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".RelativeLayoutActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name=".ListViewActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ShortCutActivity"
android:label="AutoSms">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
提前感谢您的帮助。