2011.07.08(5)——— android shortcut
2011.07.08(5)——— android shortcut
参考:http://www.bangchui.org/read.php?tid=13625
http://www.imobilebbs.com/wordpress/?p=1156
Android 操作系统对于<intent-filter>含有下列属性的Activity会在应用程序管理器(Launcher)显示一项,一般这个Activity对应于某个应用的主Activity。
<action android:name=”android.intent.action.MAIN” /><category android:name=”android.intent.category.LAUNCHER” />
<activity android:name=".app.LauncherShortcuts" android:label="@string/shortcuts"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.SAMPLE_CODE" /> </intent-filter> </activity> <activity-alias android:name=".app.CreateShortcuts" android:targetActivity=".app.LauncherShortcuts" android:label="@string/sample_shortcuts"> <intent-filter> <action android:name="android.intent.action.CREATE_SHORTCUT" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity-alias>
if (Intent.ACTION_CREATE_SHORTCUT.equals(action)){ setupShortcut(); finish(); return;} ...private void setupShortcut() { // First, set up the shortcut intent. //For this example, we simply create an intent that // will bring us directly back to this activity. //A more typical implementation would use a // data Uri in order to display a more specific result, //or a custom action in order to // launch a specific operation. Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); shortcutIntent.setClassName(this, this.getClass().getName()); shortcutIntent.putExtra(EXTRA_KEY, "ApiDemos Provided This Shortcut"); // Then, set up the container intent (the response to the caller) Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.shortcut_name)); Parcelable iconResource = Intent.ShortcutIconResource.fromContext( this, R.drawable.app_sample_code); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); // Now, return the result to the launcher setResult(RESULT_OK, intent);}