2010-07-22 85 views
2

在我的android應用程序中,我通過代碼創建了快捷方式以在我的應用程序中執行某些活動。我通過使用廣播來實現此功能:將他的應用程序添加到「添加到主屏幕」/「快捷方式」部分

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

所以我的主要問題是下一個:

這怎麼可能註冊這個菜單。我想在清單中添加一些行,但無法看到在哪裏做!

非常感謝您的幫助!

順便說一句,還有一個第二個問題:一旦我這樣做會成功,我可以在我的菜單中添加不同數量的快捷方式(想象一下,我想爲多帳戶Twitter客戶端做這件事,喜歡爲此列表中的每個Twitter帳戶查看不同的內容)。因此,快捷方式的編號是經過計算的。

回答

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

至於你的第二問題:

我不知道該如何實現你問什麼了,但一個可能的解決方案可能是讓您的CreateShortcuts活動(或等效活動)打開一個對話框,其中包含可能的選擇,您的活動將從中返回與所選項目對應的快捷方式。當然有一些額外的信息(請參閱Intent.putExtra()),詳細說明哪個項目,在你的情況下twitter用戶,用戶選擇。

相關問題