Android程序開發(fā)之手機(jī)APP創(chuàng)建桌面快捷方式
預(yù)覽效果圖:
需要權(quán)限:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
配置文件:AndroidManifest.xml
<activity android:name="com.myself.news.activity.GuideActivity" android:label="@string/title_activity_guide" > <intent-filter> <action android:name="com.myself.news.ACTION_HOME" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
在應(yīng)用的閃屏頁面Activity的 oncreate方法調(diào)用 installShortcut();
代碼:
// 創(chuàng)建快捷方式 // com.android.launcher.permission.INSTALL_SHORTCUT private void installShortcut() { // 判斷有沒有創(chuàng)建過快捷方式 boolean isCreated = SharedPreferencesUtils.getBoolean(this, GlobalConstantsUtils.PREF_IS_SHORTCUT_INTALLED, false); // 判斷是否已經(jīng)創(chuàng)建過 if (!isCreated) { // 發(fā)廣播 Intent intent = new Intent(); intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); // 圖標(biāo) // 根據(jù)資源文件id生成Bitmap對象 intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory .decodeResource(getResources(), R.drawable.ic_launcher)); // 名稱 intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "手機(jī)安全衛(wèi)士"); // 動(dòng)作 Intent actionIntent = new Intent(); // 跳到主頁面 actionIntent.setAction(GlobalConstantsUtils.ACTION_HOME); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent); sendBroadcast(intent); // 標(biāo)記已經(jīng)創(chuàng)建過快捷方式,下次不再創(chuàng)建 SharedPreferencesUtils.setBoolean(this, GlobalConstantsUtils.PREF_IS_SHORTCUT_INTALLED, true); } }
常量工具類GlobalConstantsUtils:
public static final String PREF_IS_SHORTCUT_INTALLED = "is_shortcut_intalled";// 是否已經(jīng)創(chuàng)建快捷方式 public static final String ACTION_HOME = "com.myself.news.ACTION_HOME";// 跳轉(zhuǎn)到主頁面的ACTION
相關(guān)文章
Android三種方式生成矢量圖之VectorDrawable類使用詳解
這篇文章主要介紹了Android三種方式生成矢量圖的VectorDrawable類,2014年6月26日的I/O?2014開發(fā)者大會上谷歌正式推出了Android?L,它帶來了全新的設(shè)計(jì)語言Material?Design,新的API也提供了這個(gè)類VectorDrawable2023-02-02Android進(jìn)階之使用時(shí)間戳計(jì)算時(shí)間差
這篇文章主要為大家詳細(xì)介紹了Android進(jìn)階之使用時(shí)間戳計(jì)算時(shí)間差,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12Android編程基礎(chǔ)之Menu功能菜單設(shè)計(jì)實(shí)例
這篇文章主要介紹了Android編程基礎(chǔ)之Menu功能菜單,結(jié)合實(shí)例形式分析了基本的Menu功能菜單原理、定義與響應(yīng)機(jī)制,需要的朋友可以參考下2016-10-10Android實(shí)現(xiàn)復(fù)制Assets文件到SD卡
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)復(fù)制Assets文件到SD卡,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12Android 自定義輸入支付密碼的軟鍵盤實(shí)例代碼
這篇文章主要介紹了Android 自定義輸入支付密碼的軟鍵盤實(shí)例代碼的相關(guān)資料,并附簡單實(shí)例代碼和實(shí)現(xiàn)效果圖,需要的朋友可以參考下2016-11-11android 設(shè)置圓角圖片實(shí)現(xiàn)代碼
在android應(yīng)用開發(fā)中,可能是美化需要,圖片需要處理成圓角,本文將給出實(shí)現(xiàn)代碼,開發(fā)中的遇到此問題的朋友可以參考下2012-11-11