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

发布于 2024-09-10 14:44:21 字数 706 浏览 3 评论 0原文

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

    intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    sendBroadcast(intent);

这很酷,真的很有效!

现在我想做一些不同的事情:我已经看到,当您长按主页时,某些操作可以“注册”到 Android 菜单中的某个位置,如下所示

: androidtapp.com/wp-content/uploads/2010/02/UltimateFaves-Add-Home-Screen-Shortcut.jpg" rel="nofollow noreferrer">http://www.androidtapp.com/wp-content/uploads/2010 /02/UltimateFaves-Add-Home-Screen-Shortcut.jpg

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

如何注册此菜单。我想清单中需要添加一些行,但看不到在哪里添加!

非常感谢您的帮助!

顺便说一句,还有一个次要问题:一旦我成功做到这一点,我可以在菜单中添加不同数量的快捷方式吗(想象一下,我想为多帐户 Twitter 客户端这样做,我希望看到一个此列表中的每个 Twitter 帐户都不同。)因此快捷方式的数量是通过编程计算的。

In my android application, I create shortcuts by code to some activities within my application. I do this feature by using the broadcast:

    intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    sendBroadcast(intent);

and that's cool, that really work!

Now I would like to do something different: I have seen that some actions can "register" somewhere to be added in the Android menu, when you long press on the Home like this one:

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

So my main question is the next one:

How is that possible to register for this menu. I guess there is some line to add in the manifest, but cannot see where to do that!

Thank a lot for any help!

BTW, there is a secondary question: once i will have succeed doing that, may I add a different number of shortcuts in my menu ( imagine That I would like to do that for a multi-account twitter client, I would like to see a different for each twitter account in this list.) So the number of shortcut is programmaticaly computed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少女净妖师 2024-09-17 14:44:21

刚刚在 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>

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>
冰葑 2024-09-17 14:44:21

至于你的第二个问题:

我不知道如何准确地实现你所要求的,但一种可能的解决方案可能是让你的 CreateShortcuts 活动(或同等活动)打开一个包含可能选择的对话框,你的活动将从中返回与所选项目对应的快捷方式。当然,还有一些附加信息(请参阅 Intent.putExtra()),详细说明用户选择的项目(在您的情况下是 twitter 用户)。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文