Android创建快捷方式实现
2014-07-29 18:51
393 查看
/** * create icon on desktop */ private void createShortcutIcon() { boolean isAdded = isInstallShortcut(); boolean cIsAdded = ConfigMng.getInstance().loadBooleanKey(ConfigMng.APP_SHORT_CUT_ADDED, false); if (isAdded || cIsAdded) { return; } Intent shortcutIntent = new Intent(getApplicationContext(), LoadingActivity.class.getClass()); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); shortcutIntent.setAction("android.intent.action.MAIN"); shortcutIntent.addCategory("android.intent.category.LAUNCHER"); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icon)); addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); getApplicationContext().sendBroadcast(addIntent); // save status ConfigMng.getInstance().saveBooleanKey(ConfigMng.APP_SHORT_CUT_ADDED, true); ConfigMng.getInstance().commit(); } private boolean isInstallShortcut() { boolean isInstallShortcut = false; final ContentResolver cr = getContentResolver(); final String AUTHORITY = "com.android.launcher.settings"; final String AUTHORITY2 = "com.android.launcher2.settings"; final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/favorites?notify=true"); final Uri CONTENT_URI2 = Uri.parse("content://" + AUTHORITY2 + "/favorites?notify=true"); Cursor c = cr.query(CONTENT_URI2, new String[] { "title", "iconResource" }, "title=?", new String[] { getString(R.string.app_name) }, null); if (c == null) { c = cr.query(CONTENT_URI, new String[] { "title", "iconResource" }, "title=?", new String[] { getString(R.string.app_name) }, null); } if (c != null && c.getCount() > 0) { isInstallShortcut = true; } return isInstallShortcut; }
相关文章推荐
- 解析Android应用启动后自动创建桌面快捷方式的实现方法
- android编程实现为程序创建快捷方式的方法
- Android编程实现创建,删除,判断快捷方式的方法
- Android中创建快捷方式及删除快捷方式实现方法
- 自己实现快捷方式文件的创建
- Android创建和删除桌面快捷方式
- android系统中,创建任意应用的快捷方式(shortcut)
- Android创建和删除桌面快捷方式
- android--创建快捷方式和判断是否已经创建
- Android创建和删除桌面快捷方式
- android实现应用程序无图标(快捷方式)问题
- Android创建和删除桌面快捷方式
- 关于android创建快捷方式会启动两个应用的问题(二)
- 解决三星I9000手机下Android版UCWEB老是提示创建桌面快捷方式的问题
- [Android]为指定的应用创建桌面快捷方式
- 批处理实现c/s程序部署,以及创建桌面快捷方式
- 如何编程实现在快速启动栏创建快捷方式
- Android创建快捷方式(shortcut)
- Android创建和删除桌面快捷方式
- 关于android创建快捷方式会启动两个应用的问题(一)