Adding his application to the “add to Home screen”/“Shortcut” section

ぐ巨炮叔叔 提交于 2019-12-06 14:07:27

Just found my answer in the SDK samples:

    <!-- 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>

As for your secondary question:

I don't know how to achieve exactly what you are asking for, but one possible solution might be to have your CreateShortcuts activity (or equivalent) open up a dialog with the possible choices, from which your activity would return a shortcut corresponding to the selected item. Of course with some additional info (see Intent.putExtra()) detailing which item, in your case twitter user, the user selected.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!