将他的应用程序添加到"添加到主屏幕"/"快捷方式"部分

Waz*_*_Be 2 shortcuts android manifest

在我的Android应用程序中,我通过代码为我的应用程序中的某些活动创建快捷方式.我通过使用广播来实现此功能:

    intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    sendBroadcast(intent);
Run Code Online (Sandbox Code Playgroud)

这太酷了,真的有用!

现在我想做些不同的事:我已经看到了一些行动可以"注册"的地方在Android菜单,当你长按在这样一个家庭要添加:

http://www.androidtapp.com/wp-content/uploads/2010/02/UltimateFaves-Add-Home-Screen-Shortcut.jpg

所以我的主要问题是下一个问题:

如何注册此菜单是可能的.我想在清单中添加了一些行,但看不到在哪里做!

非常感谢任何帮助!

顺便说一句,还有一个次要的问题:有一次我都会有成功的这样做,我可以在我的菜单中添加不同数量的快捷键(想象一下,我想这样做,对于多账号的Twitter客户端,我想看到一个此列表中的每个Twitter帐户都有所不同.)因此,快捷方式的数量是以编程方式计算的.

Waz*_*_Be 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>
Run Code Online (Sandbox Code Playgroud)