简体   繁体   English

用户如何从主屏幕中删除检测Android应用快捷方式的方法?

[英]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.

相关问题 Android:从主屏幕删除应用程序快捷方式 - Android: Remove app shortcut from home screen 如何在主屏幕中检测快捷方式 - How to detect shortcut in Home screen 如何检测应用程序已从Android Oreo上的最新版本(概述屏幕)中删除? - How to detect app is removed from recents (Overview screen) on Android Oreo? 如何从Android应用程序以编程方式向主屏幕添加WebApp快捷方式,以全屏启动WebApp - How to add a WebApp shortcut to home screen programatically from an android app, to launch WebApp in Full Screen 如何在安装时在Android手机的主屏幕上创建应用程序快捷方式 - how to create app shortcut on home screen on Android phones on installation 如何分辨android用户是否来自主屏幕应用 - how to tell if android user came from home screen app 在主屏幕上创建 android 应用程序快捷方式 - creating android app shortcut on the home screen Android应用程式捷径在主萤幕上的位置 - Position of android app shortcut on home screen 如何将应用程序的快捷方式添加到主屏幕 - How to add app's shortcut to the home screen 如何在android的主屏幕上添加快捷方式图标? - how to add shortcut icon on home screen in android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM