[英]How to detect android app shortcut is removed from the Home Screen by the user?
I am using minSdkVersion = 16 & targetSdkVersion = 25 for my app, and using the following code to create shortcuts for different Activities in my app. 我为我的应用程序使用minSdkVersion = 16&targetSdkVersion = 25,并使用以下代码在我的应用程序中为不同活动创建快捷方式。
private void addShortcut() {
//Adding shortcut for MainActivity
//on Home screen
Intent shortcutIntent = new Intent(getApplicationContext(),
MainActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "HelloWorldShortcut");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.mipmap.ic_launcher));
addIntent
.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
}
Now if the user removes any shortcut that belongs to my app from his Home Screen, I need to set a flag in my Preferences. 现在,如果用户从其主屏幕中删除了属于我的应用程序的任何快捷方式,则需要在“首选项”中设置一个标志。 So, if the user removes the shortcut I need to get notified in my app.
因此,如果用户删除了快捷方式,则需要在我的应用中得到通知。 How can this be done.
如何才能做到这一点。
using the following code to create shortcuts for different Activities in my app
使用以下代码为我的应用中的不同活动创建快捷方式
No, you are using that code to request shortcuts. 不,您正在使用该代码请求快捷方式。 The user's home screen may not support such requests.
用户的主屏幕可能不支持此类请求。 The user's home screen might ask the user for confirmation, and the user might decline to add the shortcut.
用户的主屏幕可能会要求用户进行确认,并且用户可能拒绝添加快捷方式。 And on Android 8.0+, that broadcast no longer has any effect .
在Android 8.0+上, 该广播不再起作用 。
if the user removes the shortcut I need to get notified in my app
如果用户删除了快捷方式,我需要在我的应用中得到通知
There is nothing in the Android SDK for this, sorry. 抱歉,Android SDK中没有此功能。 There is no requirement for home screens to let anyone know about changes in the mix of shortcuts created via the legacy
com.android.launcher.action.INSTALL_SHORTCUT
broadcast. 主屏幕无需让任何人知道通过旧版
com.android.launcher.action.INSTALL_SHORTCUT
广播创建的快捷键组合中的更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.