1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > android 查询快捷方式 android桌面快捷方式的创建和查询

android 查询快捷方式 android桌面快捷方式的创建和查询

时间:2023-02-10 05:19:21

相关推荐

android 查询快捷方式 android桌面快捷方式的创建和查询

桌面快捷方式的创建

// 内置的在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);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。