Android程序開發(fā)之手機APP創(chuàng)建桌面快捷方式
更新時間:2016年04月18日 09:15:38 作者:Jusenr/榮雪-rongsnow
這篇文章主要介紹了Android程序開發(fā)之手機APP創(chuàng)建桌面快捷方式 的相關(guān)資料,需要的朋友可以參考下
預(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");
// 圖標
// 根據(jù)資源文件id生成Bitmap對象
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory
.decodeResource(getResources(), R.drawable.ic_launcher));
// 名稱
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "手機安全衛(wèi)士");
// 動作
Intent actionIntent = new Intent();
// 跳到主頁面
actionIntent.setAction(GlobalConstantsUtils.ACTION_HOME);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent);
sendBroadcast(intent);
// 標記已經(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è)計語言Material?Design,新的API也提供了這個類VectorDrawable2023-02-02
Android編程基礎(chǔ)之Menu功能菜單設(shè)計實例
這篇文章主要介紹了Android編程基礎(chǔ)之Menu功能菜單,結(jié)合實例形式分析了基本的Menu功能菜單原理、定義與響應(yīng)機制,需要的朋友可以參考下2016-10-10
Android實現(xiàn)復(fù)制Assets文件到SD卡
這篇文章主要為大家詳細介紹了Android實現(xiàn)復(fù)制Assets文件到SD卡,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-12-12

