Android-从adb创建快捷方式 [英] Android - Create shortcut from adb

查看:891
本文介绍了Android-从adb创建快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过adb为正在开发的应用程序创建快捷方式。

I want to create a shortcut via adb for an application I'm developing.

我在 Grepcode 来查看Android预期如何格式化。
我还检查了 AM文档尝试创建

I have looked in Grepcode to see how the intent Android is expecting to be formatted. I also checked the AM documentation to try to create the intent required.

到目前为止,我在下面的一行中做了很多修改,但这似乎是最合适的。

So far I got a lot of variations of the line below, but this one seems the most appropriate.

adb -d shell am broadcast \
-a com.android.launcher.action.INSTALL_SHORTCUT \
--es Intent.EXTRA_SHORTCUT_NAME "<shortcut-name>" \
--esn Intent.EXTRA_SHORTCUT_ICON_RESOURCE \
<package-name>/.activity

我已将 EXTRA_SHORTCUT_ICON_RESOURCE 保留为空,因为Android应该搜索包本身并使用在那里定义的app_icon。

I have left the EXTRA_SHORTCUT_ICON_RESOURCE null, since Android should search the package itself and use the app_icon defined there.

命令运行并生成

Broadcasting: Intent { act=com.android.launcher.action.INSTALL_SHORTCUT cmp=<package-name>/.activity (has extras) }
Broadcast completed: result=0

没有在主屏幕上添加任何快捷方式,并且我想它与命令的开关有关。

No shortcut is added to the main screen, and I suppose it has something to do with the switches of the command.

任何人都遇到过这样的情况?

Anyone has come across anything like this?

任何帮助都非常感谢。

-JK

推荐答案

使用默认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);

这篇关于Android-从adb创建快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆