在我的Android应用程序中,我通过代码为我的应用程序中的某些活动创建快捷方式。我通过使用广播来实现此功能:
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
这很酷,真的有用!
现在我想做一些不同的事情:我已经看到一些动作可以“注册”某个地方添加到Android菜单中,当你长时间按下Home时就像这样:
http://www.androidtapp.com/wp-content/uploads/2010/02/UltimateFaves-Add-Home-Screen-Shortcut.jpg
所以我的主要问题是下一个问题:
如何注册此菜单。我想在清单中添加了一些行,但看不到在哪做!
非常感谢您的帮助!
顺便说一下,还有一个次要问题:一旦我能成功做到这一点,我可以在菜单中添加不同数量的快捷方式(想象一下,我想为多账户的Twitter客户端做这个,我希望查看此列表中每个Twitter帐户的不同。)因此,快捷方式的数量是以编程方式计算的。答案 0 :(得分:8)
刚刚在SDK示例中找到了我的答案:
<!-- This section of sample code shows how your application can add shortcuts to -->
<!-- the launcher (home screen). Shortcuts have a three step life cycle. -->
<!-- 1. Your application offers to provide shortcuts to the launcher. When -->
<!-- the user installs a shortcut, an activity within your application -->
<!-- generates the actual shortcut and returns it to the launcher, where it -->
<!-- is shown to the user as an icon. -->
<!-- 2. Any time the user clicks on an installed shortcut, an intent is sent. -->
<!-- Typically this would then be handled as necessary by an activity within -->
<!-- your application. -->
<!-- 3. The shortcut is deleted. There is no notification to your application. -->
<!-- In order provide shortcuts from your application, you provide three things: -->
<!-- 1. An intent-filter declaring your ability to provide shortcuts -->
<!-- 2. Code within the activity to provide the shortcuts as requested -->
<!-- 3. Code elsewhere within your activity, if appropriate, to receive -->
<!-- intents from the shortcut itself. -->
<activity android:name=".LauncherShortcuts"
android:label="launchers">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.SAMPLE_CODE" />
</intent-filter>
</activity>
<!-- It is recommended that you use an activity-alias to provide the "CREATE_SHORTCUT" -->
<!-- intent-filter. This gives you a way to set the text (and optionally the -->
<!-- icon) that will be seen in the launcher's create-shortcut user interface. -->
<activity-alias android:name=".CreateShortcuts"
android:targetActivity=".LauncherShortcuts"
android:label="test">
<!-- This intent-filter allows your shortcuts to be created in the launcher. -->
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
答案 1 :(得分:1)
至于你的第二个问题:
我不知道如何准确地实现您的要求,但一种可能的解决方案可能是让您的CreateShortcuts活动(或等效的)打开一个包含可能选项的对话框,您的活动将从中返回一个快捷方式对应于所选项目。当然还有一些额外的信息(参见Intent.putExtra()),详细说明用户所选择的项目,在您的情况下是Twitter用户。