Android編程實現(xiàn)創(chuàng)建,刪除,判斷快捷方式的方法
本文實例講述了Android編程實現(xiàn)創(chuàng)建,刪除,判斷快捷方式的方法。分享給大家供大家參考,具體如下:
/** * 為程序創(chuàng)建桌面快捷方式 ,這樣寫,在程序卸載的時候,快捷方式也會一并刪除 */ 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的第二個參數(shù)必須加上點號(.),否則快捷方式無法啟動相應(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)); // 快捷方式的圖標 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ā)入門與進階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
相關(guān)文章
WindowManagerService服務(wù)是如何以堆棧的形式來組織窗口
我們知道,在Android系統(tǒng)中,Activity是以堆棧的形式組織在ActivityManagerService服務(wù)中的;在本文中,我們就詳細分析WindowManagerService服務(wù)是如何以堆棧的形式來組織窗口的2013-01-01關(guān)于AndroidStudio新建與編譯項目速度慢解決辦法
這篇文章主要介紹了關(guān)于AndroidStudio新建與編譯項目速度慢的解決辦法,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-10-10Android入門之IntentService的使用教程詳解
IntentService的生命周期中有一個非常好的方法-onHandleIntent方法,它是一個abstract方法,開發(fā)者在實現(xiàn)IntentService時可以覆蓋它來處理“長事務(wù)”。本文就來聊聊IntentService的使用,需要的可以參考一下2022-12-12Android獲取apk簽名指紋的md5值(防止重新被打包)的實現(xiàn)方法
這篇文章主要介紹了Android獲取apk簽名指紋的md5值以防止重新被打包的實現(xiàn)方法,結(jié)合實例形式詳細分析了Android獲取apk md5值的常用技巧,需要的朋友可以參考下2016-07-07Android 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