iGo*_*oDa 4 android android-intent android-6.0-marshmallow
我试图通过服务为我的应用程序创建一个快捷方式.以下代码正在处理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);
Run Code Online (Sandbox Code Playgroud)
在SDK <= 21创建快捷方式中,如果已存在,则不会创建其他实例.
在SDK = 23快捷方式将仅如果我按创建shorcut并再次尝试创建快捷方式.如果我重新启动该设备,然后再次尝试创建快捷方式复制或.
我尝试先卸载快捷方式,但没有成功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);
Run Code Online (Sandbox Code Playgroud)
这是服务实现:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
Android 6改变了捷径创作政治吗?我在文档上找不到任何内容.
[ 更新 ]我尝试通过单击示例应用程序上的按钮来创建此快捷方式,但这仍然会发生.单击创建的快捷方式后,shorcut将复制,然后再次尝试创建它.重启设备也会发生同样的事情.
[ UPDATE2 ]我正在查看Launcher3谷歌应用程序的grep代码,我发现快捷方式安装调用registerSessionCallback,这取决于调用线程.这些新变化可能会成为问题吗?
对于那些陷入同样问题的人:
谷歌删除了对Launcher3和谷歌上的卸载快捷方式的支持,现在是Android M上的Launcher.
此外,快捷方式的重复是最新的Android M版本(MRA58K)和现在开发团队手中的问题.
你们可以在这里关注这个问题,https://code.google.com/p/android/issues/detail?id = 179697
[ 更新 ]谷歌刚刚解决了这个问题,它将在下一个版本上发布.
| 归档时间: |
|
| 查看次数: |
1448 次 |
| 最近记录: |