解决方法
发送INSTALL_SHORTCUT广播与产生的Intent作为额外的(在这种情况下,结果Intent直接打开一些活动).
//where this is a context (e.g. your current activity) final Intent shortcutIntent = new Intent(this,SomeActivity.class); final Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,shortcutIntent); // Sets the custom shortcut's title intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,getString(R.string.app_name)); // Set the custom shortcut icon intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(this,R.drawable.icon)); // add the shortcut intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); sendbroadcast(intent);
您的清单还需要此权限:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
原文地址:https://www.jb51.cc/android/125813.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。