Android中創(chuàng)建快捷方式代碼實例
1、添加權(quán)限(必須)
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
2、添加快捷鍵
public static void setupShortcut(Activity activity)
{
Intent shortcutIntent = new Intent(activity, MainActivity.class); //啟動首頁(launcher Activity)
Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "hello");//快捷鍵名字可以任意,不過最好為app名稱
Parcelable iconResource = Intent.ShortcutIconResource.fromContext(activity, R.drawable.ic_launcher);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
intent.putExtra("duplicate", false);//不允許重復(fù)創(chuàng)建
activity.sendBroadcast(intent);//發(fā)送廣播創(chuàng)建快捷鍵
}
3、快捷鍵也可以指向非Launcher activity,只需要在AndroidManifest中對應(yīng)的Activity 中添加如下配置
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<intent-filter>
例如可以將2 中的MainActivity 改為任意其他Activity,同時在AndroidManifest中對應(yīng)添加上述intent-filter就可以了。
- Android 創(chuàng)建/驗證/刪除桌面快捷方式(已測試可用)
- android 為應(yīng)用程序創(chuàng)建桌面快捷方式技巧分享
- 解析Android應(yīng)用啟動后自動創(chuàng)建桌面快捷方式的實現(xiàn)方法
- Android的Launcher啟動器中添加快捷方式及小部件實例
- Android添加(創(chuàng)建)、刪除及判斷是否存在桌面快捷方式的方法
- Android通過應(yīng)用程序創(chuàng)建快捷方式的方法
- Android實現(xiàn)向Launcher添加快捷方式的方法
- android編程實現(xiàn)為程序創(chuàng)建快捷方式的方法
- Android應(yīng)用創(chuàng)建桌面快捷方式代碼
- Android中創(chuàng)建快捷方式及刪除快捷方式實現(xiàn)方法
- Android應(yīng)用創(chuàng)建多個快捷方式
- Android編程實現(xiàn)向桌面添加快捷方式的方法
- Android編程實現(xiàn)創(chuàng)建,刪除,判斷快捷方式的方法
相關(guān)文章
Android解析相同接口返回不同格式j(luò)son數(shù)據(jù)的方法
這篇文章主要介紹了Android解析相同接口返回不同格式j(luò)son數(shù)據(jù)的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-08-08
Android使用SmsManager實現(xiàn)短信發(fā)送功能
這篇文章主要為大家詳細介紹了Android使用SmsManager實現(xiàn)短信發(fā)送功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-11-11
內(nèi)存泄露導(dǎo)致Android?中setVisibility()?失效原理
這篇文章主要介紹了內(nèi)存泄露導(dǎo)致Android?中setVisibility()?失效原理,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,感興趣的小伙伴可以參考一下2022-07-07
Android自定義控件實現(xiàn)不規(guī)則區(qū)域點擊事件
這篇文章主要為大家詳細介紹了Android自定義控件實現(xiàn)不規(guī)則區(qū)域點擊事件,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-05-05
android BottomSheetDialog新控件解析實現(xiàn)知乎評論列表效果(實例代碼)
BottomSheetDialog是一個自定義的從底部滑入的對話框,這篇文章主要介紹了android BottomSheetDialog新控件解析實現(xiàn)知乎評論列表效果,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04
Android Bluetooth藍牙技術(shù)使用流程詳解
這篇文章主要介紹了Android Bluetooth藍牙技術(shù)使用流程詳解的相關(guān)資料,需要的朋友可以參考下2016-02-02

