android添加快捷方式
1.在清單文件里添加
<!-- 定義添加到桌面Launcher中 -->這個是放在主activity里邊
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
</intent-filter>
2.指定添加安裝快捷方式的權限
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
在代碼中添加:
// 創建添加快捷方式的Intent
Intent addIntent = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
String title = getResources().getString(R.string.app_name);
// 加載快捷方式的圖標
Parcelable icon = Intent.ShortcutIconResource.fromContext(
MainActivity.this, R.drawable.ic_launcher);
// 創建點擊快捷方式后操作Intent,該處當點擊創建的快捷方式后,再次啟動該程序
Intent myIntent = new Intent(MainActivity.this,
MainActivity.class);
// 設置快捷方式的標題
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
// 設置快捷方式的圖標
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
// 設置快捷方式對應的Intent
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);
// 發送廣播添加快捷方式
sendBroadcast(addIntent);來自: http://blog.csdn.net//mockingbirds/article/details/44838729
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!