且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android-从adb创建快捷方式

更新时间:2023-01-31 11:11:18

使用默认ICS启动器作为参考rence ,我发现该意图期望您没有发送的额外内容: android.intent.extra.shortcut.INTENT 。此意图是将用于启动快捷方式指向的应用程序的意图。意识到为此额外的期望类型是可打包的。到目前为止,我知道, am 无法发送这样的数据结构。

Taking the default ICS Launcher as reference, I see that the intent expects an extra which you are not sending: android.intent.extra.shortcut.INTENT. This intent is the one that will be used to start the application pointed by shortcut. Realize that the type expected for this extra is a parcelable . So far I know, am is not able to sent such data structure.

作为一种解决方法,您可以创建一个非常简单的应用程序来发送此广播。

As a workaround, you can create a very simple application to send this broadcast.

首先,添加权限< uses-permission android:name = com.android .launcher.permission.INSTALL_SHORTCUT /> 到AndroidManifest.xml

First of all, add the permission <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> to AndroidManifest.xml

然后,您可以尝试进行以下活动:

Then, you could try in activity:

Intent shortcut = new Intent(Intent.ACTION_VIEW);
shortcut.setClassName("<package-name>", "<package-name>.activity");

Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "<shortcut-name>");
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut);

sendBroadcast(intent);