Android編程實(shí)現(xiàn)創(chuàng)建,刪除,判斷快捷方式的方法
本文實(shí)例講述了Android編程實(shí)現(xiàn)創(chuàng)建,刪除,判斷快捷方式的方法。分享給大家供大家參考,具體如下:
/**
* 為程序創(chuàng)建桌面快捷方式 ,這樣寫,在程序卸載的時(shí)候,快捷方式也會(huì)一并刪除
*/
private void addShortcut() {
Intent shortcutIntent = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
// 快捷方式的名稱
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
getString(R.string.app_name));
shortcutIntent.putExtra("duplicate", false); // 不允許重復(fù)創(chuàng)建
/*
* shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(
* getApplicationContext(), SplashActivity.class));
*/
// 注意: ComponentName的第二個(gè)參數(shù)必須加上點(diǎn)號(hào)(.),否則快捷方式無(wú)法啟動(dòng)相應(yīng)程序
ComponentName comp = new ComponentName(this.getPackageName(),
this.getPackageName() + "." + this.getLocalClassName());
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
intent.setComponent(comp));
// 快捷方式的圖標(biāo)
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(
this, R.drawable.icon_launcher);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
sendBroadcast(shortcutIntent);
}
//判斷是否已經(jīng)創(chuàng)建快捷方式
private boolean hasShortcut() {
boolean isInstallShortcut = false;
final ContentResolver resolver = this.getContentResolver();
final String AUTHORITY;
if (android.os.Build.VERSION.SDK_INT < 8) {
AUTHORITY = "com.android.launcher.settings";
} else {
AUTHORITY = "com.android.launcher2.settings";
}
final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
+ "/favorites?notify=true");
Cursor c = resolver
.query(CONTENT_URI,
new String[] { "title", "iconResource" },
"title=?",
new String[] { this.getString(R.string.app_name).trim() },
null);
if (c != null && c.getCount() > 0) {
isInstallShortcut = true;
}
return isInstallShortcut;
}
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問(wèn)題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
相關(guān)文章
WindowManagerService服務(wù)是如何以堆棧的形式來(lái)組織窗口
我們知道,在Android系統(tǒng)中,Activity是以堆棧的形式組織在ActivityManagerService服務(wù)中的;在本文中,我們就詳細(xì)分析WindowManagerService服務(wù)是如何以堆棧的形式來(lái)組織窗口的2013-01-01
關(guān)于AndroidStudio新建與編譯項(xiàng)目速度慢解決辦法
這篇文章主要介紹了關(guān)于AndroidStudio新建與編譯項(xiàng)目速度慢的解決辦法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10
Android入門之IntentService的使用教程詳解
IntentService的生命周期中有一個(gè)非常好的方法-onHandleIntent方法,它是一個(gè)abstract方法,開發(fā)者在實(shí)現(xiàn)IntentService時(shí)可以覆蓋它來(lái)處理“長(zhǎng)事務(wù)”。本文就來(lái)聊聊IntentService的使用,需要的可以參考一下2022-12-12
基于Flutter實(shí)現(xiàn)多邊形和多角星組件
開發(fā)中,免不了會(huì)用到多邊形、多角星等圖案,比較常用的多邊形比如雷達(dá)圖、多角星比如評(píng)價(jià)星級(jí)的五角星等,本文章就使用Flutter繪制封裝一個(gè)這樣的組件,需要的可以參考一下2022-05-05
Android獲取apk簽名指紋的md5值(防止重新被打包)的實(shí)現(xiàn)方法
這篇文章主要介紹了Android獲取apk簽名指紋的md5值以防止重新被打包的實(shí)現(xiàn)方法,結(jié)合實(shí)例形式詳細(xì)分析了Android獲取apk md5值的常用技巧,需要的朋友可以參考下2016-07-07
android nfc常用標(biāo)簽讀取總結(jié)
NFC(Near Field Communication,近場(chǎng)通信)是一種數(shù)據(jù)傳輸技術(shù)這篇文章主要介紹了android nfc常用標(biāo)簽讀取總結(jié),有興趣的可以了解一下。2016-12-12
Android Service判斷設(shè)備聯(lián)網(wǎng)狀態(tài)詳解
本文主要介紹Android Service判斷聯(lián)網(wǎng)狀態(tài),這里提供了相關(guān)資料并附有示例代碼,有興趣的小伙伴可以參考下,幫助開發(fā)相關(guān)應(yīng)用功能2016-08-08

