【问题标题】:Adding his application to the "add to Home screen"/"Shortcut" section将他的应用程序添加到“添加到主屏幕”/“快捷方式”部分
【发布时间】:2010-07-22 10:22:41
【问题描述】:

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

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

这很酷,真的很管用!

现在我想做一些不同的事情:当你像这样长按 Home 时,我已经看到一些动作可以“注册”到某个地方添加到 Android 菜单中:

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

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

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

非常感谢您的帮助!

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

【问题讨论】:

    标签: android manifest shortcut


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      关于你的第二个问题:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-10-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-24
        • 1970-01-01
        • 2018-06-09
        • 1970-01-01
        相关资源
        最近更新 更多