Xml代碼
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
在你的項目清單中看到如下代碼代表這個activity是本應用的啟動activity。系統會自動為建立捷徑。在你使用一些應用時它有時會讓你建立捷徑 比如 UC瀏覽器.這是怎麼做的呢?其實也很簡單。只需:
Java代碼
/**
* 這兩行代碼說明你想幹嘛
*/
Uri uri = Uri.parse("tel:0800000123");
Intent myIntent = new Intent(Intent.ACTION_DIAL, uri);
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
Parcelable icon = Intent.ShortcutIconResource.
fromContext(this,R.drawable.beach); // 擷取快速鍵的表徵圖
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// 捷徑的表徵圖
//shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON, R.drawable.beach); //可以代替上面兩行代碼
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "捷徑");// 捷徑的標題
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);// 捷徑的動作
sendBroadcast(shortcut);// 完了你還可以告訴系統你建立了個捷徑
如果你還想在建立捷徑欄中添加一個你自己的條目 比如
你也只需在資訊清單檔中加入:(你要建立一個activity哦 NoneShortcut)
Xml代碼
<activity android:name=".NoneShortcut" android:icon="@drawable/photo6" android:label="哈哈">
<intent-filter >
<action android:name="android.intent.action.CREATE_SHORTCUT"/>
</intent-filter>
</activity>
本文出自“sunney2012”