android 為應(yīng)用程序創(chuàng)建桌面快捷方式技巧分享
更新時間:2012年12月05日 15:36:48 作者:
手機裝的軟件過多,找起來很不方便,所以在主頁面有一個快捷方式的話會很不錯的,本文將介紹如何實現(xiàn),需要了解跟多的朋友可以參考下
我們開發(fā)一款軟件后,如果手機裝的軟件過多,去翻的話會很難翻的,所以,在主頁面有一個快捷方式的話會很不錯的,下面是詳細(xì)代碼:
/**
* 創(chuàng)建桌面快捷方式
*/
private void createShortcut() {
SharedPreferences setting = getSharedPreferences("silent.preferences", 0);
// 判斷是否第一次啟動應(yīng)用程序(默認(rèn)為true)
boolean firstStart = setting.getBoolean("FIRST_START", true);
// 第一次啟動時創(chuàng)建桌面快捷方式
if (firstStart) {
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
// 快捷方式的名稱
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name2));
// 不允許重復(fù)創(chuàng)建
shortcut.putExtra("duplicate", false);
// 指定快捷方式的啟動對象
ComponentName comp = new ComponentName(this.getPackageName(), "." + this.getLocalClassName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
// 快捷方式的圖標(biāo)
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.zhangxy);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
// 發(fā)出廣播
sendBroadcast(shortcut);
// 將第一次啟動的標(biāo)識設(shè)置為false
Editor editor = setting.edit();
editor.putBoolean("FIRST_START", false);
// 提交設(shè)置
editor.commit();
}
}
然后在onCreate()方法里加上上面方法名稱就行了:
// 安裝后第一次啟動時創(chuàng)建桌面快捷方式
createShortcut();
最后在AndroidManifest.xml里加上創(chuàng)建快捷方式的權(quán)限就行了:
<!-- 創(chuàng)建桌面快捷方式的權(quán)限 -->
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
復(fù)制代碼 代碼如下:
/**
* 創(chuàng)建桌面快捷方式
*/
private void createShortcut() {
SharedPreferences setting = getSharedPreferences("silent.preferences", 0);
// 判斷是否第一次啟動應(yīng)用程序(默認(rèn)為true)
boolean firstStart = setting.getBoolean("FIRST_START", true);
// 第一次啟動時創(chuàng)建桌面快捷方式
if (firstStart) {
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
// 快捷方式的名稱
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name2));
// 不允許重復(fù)創(chuàng)建
shortcut.putExtra("duplicate", false);
// 指定快捷方式的啟動對象
ComponentName comp = new ComponentName(this.getPackageName(), "." + this.getLocalClassName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
// 快捷方式的圖標(biāo)
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.zhangxy);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
// 發(fā)出廣播
sendBroadcast(shortcut);
// 將第一次啟動的標(biāo)識設(shè)置為false
Editor editor = setting.edit();
editor.putBoolean("FIRST_START", false);
// 提交設(shè)置
editor.commit();
}
}
然后在onCreate()方法里加上上面方法名稱就行了:
復(fù)制代碼 代碼如下:
// 安裝后第一次啟動時創(chuàng)建桌面快捷方式
createShortcut();
最后在AndroidManifest.xml里加上創(chuàng)建快捷方式的權(quán)限就行了:
復(fù)制代碼 代碼如下:
<!-- 創(chuàng)建桌面快捷方式的權(quán)限 -->
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
您可能感興趣的文章:
- Android應(yīng)用創(chuàng)建桌面快捷方式代碼
- Android如何創(chuàng)建桌面快捷方式
- Android程序開發(fā)之手機APP創(chuàng)建桌面快捷方式
- Android添加(創(chuàng)建)、刪除及判斷是否存在桌面快捷方式的方法
- 解析Android應(yīng)用啟動后自動創(chuàng)建桌面快捷方式的實現(xiàn)方法
- Android 創(chuàng)建/驗證/刪除桌面快捷方式(已測試可用)
- Android編程實現(xiàn)向桌面添加快捷方式的方法
- Android編程添加快捷方式(Short)到手機桌面的方法(含添加,刪除及查詢)
- Android編程實現(xiàn)創(chuàng)建,刪除,判斷快捷方式的方法
- Android應(yīng)用創(chuàng)建多個快捷方式
- Android實現(xiàn)向Launcher添加快捷方式的方法
- Android編程創(chuàng)建桌面快捷方式的常用方法小結(jié)【2種方法】
相關(guān)文章
Android layoutAnimation詳解及應(yīng)用
這篇文章主要介紹了Android layoutAnimation詳解及應(yīng)用的相關(guān)資料,需要的朋友可以參考下2017-05-05Notification消息通知 自定義消息通知內(nèi)容布局
這篇文章主要為大家詳細(xì)介紹了Notification消息通知,消息合并且顯示條數(shù),自定義消息通知內(nèi)容布局,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-09-09Android開發(fā)Input系統(tǒng)觸摸事件分發(fā)
這篇文章主要為大家介紹了Android開發(fā)Input系統(tǒng)觸摸事件分發(fā)示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-03-03Android編程實現(xiàn)的首頁左右滑動切換功能示例
這篇文章主要介紹了Android編程實現(xiàn)的首頁左右滑動切換功能,涉及Android事件監(jiān)聽及響應(yīng)相關(guān)操作技巧,需要的朋友可以參考下2017-07-07