Android桌面 快捷方式的删除
2014-11-04 16:22
351 查看
快捷方式的删除规则:
首先根据Intent.EXTRA_SHORTCUT_NAME来查找,
然后再比对intent是否一致(Action、data、type、package、component、categories)
比对正确则删除;
UninstallShortcutReceiver.java类
首先根据Intent.EXTRA_SHORTCUT_NAME来查找,
然后再比对intent是否一致(Action、data、type、package、component、categories)
比对正确则删除;
UninstallShortcutReceiver.java类
private static void removeShortcut(Context context, Intent data, final SharedPreferences sharedPrefs) { Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true); if (intent != null && name != null) { final ContentResolver cr = context.getContentResolver(); Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, new String[] { LauncherSettings.Favorites._ID, LauncherSettings.Favorites.INTENT }, <span style="color:#FF0000;">LauncherSettings.Favorites.TITLE + "=?", new String[] { name }</span>, null); final int intentIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.INTENT); final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID); boolean changed = false; try { while (c.moveToNext()) { try { if (intent.filterEquals(Intent.parseUri(c.getString(intentIndex), 0))) { final long id = c.getLong(idIndex); final Uri uri = LauncherSettings.Favorites.getContentUri(id, false); cr.delete(uri, null, null); changed = true; if (!duplicate) { break; } } } catch (URISyntaxException e) { // Ignore } } } finally { c.close(); } if (changed) { cr.notifyChange(LauncherSettings.Favorites.CONTENT_URI, null); Toast.makeText(context, context.getString(R.string.shortcut_uninstalled, name), Toast.LENGTH_SHORT).show(); } // Remove any items due to be animated boolean appRemoved; Set<String> newApps = new HashSet<String>(); newApps = sharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps); synchronized (newApps) { do { appRemoved = newApps.remove(intent.toUri(0).toString()); } while (appRemoved); } if (appRemoved) { final Set<String> savedNewApps = newApps; new Thread("setNewAppsThread-remove") { public void run() { SharedPreferences.Editor editor = sharedPrefs.edit(); editor.putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, savedNewApps); if (savedNewApps.isEmpty()) { // Reset the page index if there are no more items editor.putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1); } editor.commit(); } }.start(); } } }和intent.filterEquals
/** * Determine if two intents are the same for the purposes of intent * resolution (filtering). That is, if their action, data, type, * class, and categories are the same. This does <em>not</em> compare * any extra data included in the intents. * * @param other The other Intent to compare against. * * @return Returns true if action, data, type, class, and categories * are the same. */ public boolean filterEquals(Intent other) { if (other == null) { return false; } if (mAction != other.mAction) { if (mAction != null) { if (!mAction.equals(other.mAction)) { return false; } } else { if (!other.mAction.equals(mAction)) { return false; } } } if (mData != other.mData) { if (mData != null) { if (!mData.equals(other.mData)) { return false; } } else { if (!other.mData.equals(mData)) { return false; } } } if (mType != other.mType) { if (mType != null) { if (!mType.equals(other.mType)) { return false; } } else { if (!other.mType.equals(mType)) { return false; } } } if (mPackage != other.mPackage) { if (mPackage != null) { if (!mPackage.equals(other.mPackage)) { return false; } } else { if (!other.mPackage.equals(mPackage)) { return false; } } } if (mComponent != other.mComponent) { if (mComponent != null) { if (!mComponent.equals(other.mComponent)) { return false; } } else { if (!other.mComponent.equals(mComponent)) { return false; } } } if (mCategories != other.mCategories) { if (mCategories != null) { if (!mCategories.equals(other.mCategories)) { return false; } } else { if (!other.mCategories.equals(mCategories)) { return false; } } } return true; }
相关文章推荐
- Android创建和删除桌面快捷方式
- Android创建和删除桌面快捷方式
- Android创建和删除桌面快捷方式 【转】
- android添加删除桌面快捷方式
- Android创建和删除桌面快捷方式
- android程序卸载后无法删除桌面快捷方式的解决办法
- Android创建和删除桌面快捷方式
- Android删除桌面上的快捷方式
- Android创建和删除桌面快捷方式
- Android桌面快捷方式图标生成与删除,使用Intent与launcher交互
- Android创建和删除桌面快捷方式
- Android桌面快捷方式图标生成与删除,使用Intent与launcher交互
- Android创建和删除桌面快捷方式
- Android创建和删除桌面快捷方式
- Android 向桌面添加删除快捷方式
- Android创建和删除桌面快捷方式
- Android创建和删除桌面快捷方式
- Android桌面快捷方式图标生成与删除,使用Intent与launcher交互
- android程序卸载后无法删除桌面快捷方式的解决办法
- android桌面快捷方式添加 删除 更新 自动运行