gpt4 book ai didi

Android M 快捷安装/卸载重复

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:27:51 26 4
gpt4 key购买 nike

我正在尝试通过服务为我的应用程序创建快捷方式。以下代码适用于 SDK <= 21 , 但它在 SDK = 23 上无法正常工作

快捷方式的创建是这样完成的:

        Intent shortcutIntent = new Intent(this, MainActivity.class);
shortcutIntent.putExtra(EXTRA_SHORTCUT_CLICKED, true); //This is only to check when the user clicked on the created shortcut
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);

Intent addIntent = new Intent();
addIntent.putExtra("duplicate", false);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "TEST");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.application_icon));
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

sendBroadcast(addIntent);

SDK <= 21快捷方式已创建,如果已经存在,则不会创建其他实例。

SDK = 23如果我按下创建的快捷方式并尝试再次创建快捷方式,或者如果我重新启动设备然后再次尝试创建快捷方式,则快捷方式只会被复制。

我尝试先卸载快捷方式,但在 SDK 23 上没有成功,如下:

        Intent shortcutIntent = new Intent(this, MainActivity.class);
shortcutIntent.putExtra(EXTRA_SHORTCUT_CLICKED, true); //This is only to check when the user clicked on the created shortcut
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);

Intent addIntent = new Intent();
addIntent.putExtra("duplicate", false);
addIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "TEST");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.application_icon));
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

sendBroadcast(addIntent);

这是服务实现:

public class MyService extends Service {

@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
createShortcut(); //This is where I create the shortcut
return super.onStartCommand(intent,flags,startId);
}
}

Android 6 是否改变了快捷方式创建策略?我在文档中找不到任何内容。

[更新] 我试图通过单击示例应用程序上的按钮来创建快捷方式,但这种情况仍然发生。单击创建的快捷方式后,快捷方式将重复,然后尝试再次创建它。重启设备会发生同样的事情。

[UPDATE2] 我正在查看 Launcher3 谷歌应用程序的 grep 代码,我发现快捷方式安装调用了 registerSessionCallback这取决于调用线程。可能是关于这些新变化的问题?

最佳答案

对于遇到同样问题的人:

Google 取消了对 Launcher3 上的卸载快捷方式的支持,Google 现在在 Android M 上支持 Launcher。

此外,快捷方式重复是最新 Android M 版本 (MRA58K) 上的一个问题,现在由开发团队处理。

你们可以在这里关注这个问题,https://code.google.com/p/android/issues/detail?id=179697

[更新] Google 刚刚修复了这个问题,它将在下一个版本中发布。

关于Android M 快捷安装/卸载重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33036774/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com