Android編程實現創(chuàng)建,刪除,判斷快捷方式的方法
更新時間:2017年02月24日 12:01:07 作者:Jacob-wj
這篇文章主要介紹了Android編程實現創(chuàng)建,刪除,判斷快捷方式的方法,結合實例形式分析了Android編程針對快捷方式的常用操作技巧,需要的朋友可以參考下
本文實例講述了Android編程實現創(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); // 不允許重復創(chuàng)建 /* * shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent( * getApplicationContext(), SplashActivity.class)); */ // 注意: ComponentName的第二個參數必須加上點號(.),否則快捷方式無法啟動相應程序 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); } //判斷是否已經創(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; }
更多關于Android相關內容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進階教程》、《Android調試技巧與常見問題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結》、《Android視圖View技巧總結》、《Android布局layout技巧總結》及《Android控件用法總結》
希望本文所述對大家Android程序設計有所幫助。
相關文章
WindowManagerService服務是如何以堆棧的形式來組織窗口
我們知道,在Android系統中,Activity是以堆棧的形式組織在ActivityManagerService服務中的;在本文中,我們就詳細分析WindowManagerService服務是如何以堆棧的形式來組織窗口的2013-01-01Android入門之IntentService的使用教程詳解
IntentService的生命周期中有一個非常好的方法-onHandleIntent方法,它是一個abstract方法,開發(fā)者在實現IntentService時可以覆蓋它來處理“長事務”。本文就來聊聊IntentService的使用,需要的可以參考一下2022-12-12Android獲取apk簽名指紋的md5值(防止重新被打包)的實現方法
這篇文章主要介紹了Android獲取apk簽名指紋的md5值以防止重新被打包的實現方法,結合實例形式詳細分析了Android獲取apk md5值的常用技巧,需要的朋友可以參考下2016-07-07Android Service判斷設備聯網狀態(tài)詳解
本文主要介紹Android Service判斷聯網狀態(tài),這里提供了相關資料并附有示例代碼,有興趣的小伙伴可以參考下,幫助開發(fā)相關應用功能2016-08-08