Android M 快捷键 install/uninstall 重复
Android M shortcut install/uninstall duplication
我正在尝试通过服务为我的应用程序创建快捷方式。
以下代码在 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 是否更改了快捷方式创建策略?我在文档中找不到任何内容。
[UPDATE] 我试图通过单击示例应用程序上的按钮来创建此快捷方式,但这种情况仍然发生。单击创建的快捷方式后,快捷方式将重复,然后尝试再次创建它。重启设备也会发生同样的事情。
[UPDATE2] 我正在查看 Launcher3 google 应用程序的 grep 代码,我发现快捷方式安装调用了 registerSessionCallback,这取决于在调用线程上。可能是关于这些新变化的问题?
对于遇到同样问题的人:
Google 删除了对 Launcher3 上的卸载快捷方式的支持,Google 现在 Android M 上的启动器。
此外,快捷键重复是最新 Android M build (MRA58K) 的一个问题,现在由开发团队处理。
大家可以关注这里,https://code.google.com/p/android/issues/detail?id=179697
[UPDATE] Google 刚刚修复了这个问题,它将在下一个版本中发布。
也许这对你们中的一些人有帮助。虽然 Google 删除了支持
用于卸载快捷方式,指向 activity-别名的快捷方式
一旦别名被禁用,仍然会被删除。 ;)
我正在尝试通过服务为我的应用程序创建快捷方式。
以下代码在 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 是否更改了快捷方式创建策略?我在文档中找不到任何内容。
[UPDATE] 我试图通过单击示例应用程序上的按钮来创建此快捷方式,但这种情况仍然发生。单击创建的快捷方式后,快捷方式将重复,然后尝试再次创建它。重启设备也会发生同样的事情。
[UPDATE2] 我正在查看 Launcher3 google 应用程序的 grep 代码,我发现快捷方式安装调用了 registerSessionCallback,这取决于在调用线程上。可能是关于这些新变化的问题?
对于遇到同样问题的人:
Google 删除了对 Launcher3 上的卸载快捷方式的支持,Google 现在 Android M 上的启动器。
此外,快捷键重复是最新 Android M build (MRA58K) 的一个问题,现在由开发团队处理。
大家可以关注这里,https://code.google.com/p/android/issues/detail?id=179697
[UPDATE] Google 刚刚修复了这个问题,它将在下一个版本中发布。
也许这对你们中的一些人有帮助。虽然 Google 删除了支持 用于卸载快捷方式,指向 activity-别名的快捷方式 一旦别名被禁用,仍然会被删除。 ;)