android圆桌面快捷方式的创建和查询
android桌面快捷方式的创建和查询
桌面快捷方式的创建
桌面快捷方式的查询
快捷方式的删除(2.1上不行),当程序删除时,系统会自动帮我们把快捷方式删除
桌面快捷方式的创建
// 内置的在2.1上不行 // Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT); Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); intent.putExtra("duplicate", false); ComponentName comp = new ComponentName(getApplicationContext(), Shortcut.class); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp)); ShortcutIconResource res = Intent.ShortcutIconResource.fromContext( getApplicationContext(), R.drawable.icon); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, res); sendBroadcast(intent);
桌面快捷方式的查询
private static final Uri CONTENT_URI = Uri.parse("content://com.android.launcher.settings/favorites?notify=true"); private static final String[] PROJECTION = { "_id", "title", "iconResource" }; private boolean hasShortCut() { ContentResolver resolver = getContentResolver(); Cursor cursor = resolver.query(CONTENT_URI, PROJECTION, "title=?", new String[] {getString(R.string.app_name)}, null); if (cursor != null && cursor.moveToFirst()) { cursor.close(); return true; } return false; }
快捷方式的删除(2.1上不行),当程序删除时,系统会自动帮我们把快捷方式删除
Intent intent = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT"); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); ComponentName comp = new ComponentName(getApplicationContext(), Shortcut.class); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp)); sendBroadcast(intent);
1 楼
1846396994
2012-04-21
总结的关于添加和删除及判断是否存在快捷方式,Android应用添加(创建)和删除及判断是否存在桌面快捷方式