Android程序開發(fā)之手機APP創(chuàng)建桌面快捷方式
更新時間:2016年04月18日 09:15:38 作者:Jusenr/榮雪-rongsnow
這篇文章主要介紹了Android程序開發(fā)之手機APP創(chuàng)建桌面快捷方式 的相關(guān)資料,需要的朋友可以參考下
預覽效果圖:

需要權(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>
在應用的閃屏頁面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啟動初始化方案App StartUp的應用詳解
這篇文章主要介紹了Android啟動初始化方案App StartUp的使用方法,StartUp是為了App的啟動提供的一套簡單、高效的初始化方案,下面我們來詳細了解2022-09-09
Android開發(fā)之圖形圖像與動畫(一)Paint和Canvas類學習
Paint類代表畫筆,用來描述圖形的顏色和風格,如線寬,顏色,透明度和填充效果等信息;Canvas類代表畫布,通過該類提供的構(gòu)造方法,可以繪制各種圖形;感興趣的朋友可以了解下啊,希望本文對你有所幫助2013-01-01
Android Recyclerview實現(xiàn)多選,單選,全選,反選,批量刪除的功能
本篇文章主要介紹了Android Recyclerview 實現(xiàn)多選,單選,全選,反選,批量刪除的功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06

