桌面快捷方式的创建
// 内置的在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);