在我的 android 应用程序中,我通过代码为应用程序中的某些 Activity 创建快捷方式。我通过使用广播来实现此功能:
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
这很酷,真的很管用!
现在我想做一些不同的事情:我已经看到,当您像这样长按主页时,某些操作可以“注册”到某个位置以添加到 Android 菜单中:
http://www.androidtapp.com/wp-content/uploads/2010/02/UltimateFaves-Add-Home-Screen-Shortcut.jpg
所以我的主要问题是下一个:
怎么可能注册这个菜单。我想在 list 中要添加一些行,但看不到在哪里添加!
非常感谢您的帮助!
顺便说一句,还有一个次要问题:一旦我成功做到这一点,我可以在我的菜单中添加不同数量的快捷方式吗(假设我想为多帐户 Twitter 客户端这样做,我想在此列表中查看每个 Twitter 帐户的不同。)所以快捷方式的数量是通过编程计算的。
最佳答案
刚刚在 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>
关于android - 将他的应用程序添加到 "add to Home screen"/"Shortcut"部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3307826/