android应用开发之桌面快捷方式
2015-01-05 16:13
417 查看
直接code
/** * has shortcut * * @return */ private boolean hasShortcut() { boolean isInstallShortcut = false; final ContentResolver cr = this.getContentResolver(); final String AUTHORITY = "com.android.launcher.settings"; final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/favorites?notify=true"); Cursor c = cr.query(CONTENT_URI, new String[] { "title", "iconResource" }, "title=?", new String[] { this .getString(R.string.app_name).trim() }, null); if (c != null && c.getCount() > 0) { isInstallShortcut = true; } return isInstallShortcut; } /** * create shortcut */ private void addShortcut() { Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); // shortcut name shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); shortcut.putExtra("duplicate", false); Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); shortcutIntent.setClassName(this, this.getClass().getName()); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); // this icon of shortcut ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); sendBroadcast(shortcut); } /** * delete shortcut */ private void delShortcut() { Intent shortcut = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT"); // this name of shortcut shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); String appClass = this.getPackageName() + "." + this.getLocalClassName(); ComponentName comp = new ComponentName(this.getPackageName(), appClass); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp)); sendBroadcast(shortcut); }调用处判断下是否有快捷方式,没有创建,即可
if (!hasShortcut()) { addShortcut(); }
相关文章推荐
- Android Launcher桌面应用快捷方式的开发
- Android Launcher桌面应用快捷方式的开发
- Android Launcher桌面应用快捷方式的开发
- Android应用开发之(如何自动在桌面创建快捷方式)
- Android Launcher研究(四)-----------桌面应用快捷方式的开发!
- Android Launcher研究(四)-----------桌面应用快捷方式的开发!
- Android应用开发之(如何自动在桌面创建快捷方式)
- Android开发:应用启动后自动创建桌面快捷方式(三星机常见)
- Android Launcher研究(四)-----------桌面应用快捷方式的开发!
- Android Launcher研究(四)-----------桌面应用快捷方式的开发!
- [高级]Android Launcher研究(一)-----------图文详解手把手教你在Windows环境下下载Android源码(Launcher为例)Android Launcher研究(四)-----------桌面应用快捷方式的开发!
- Android Launcher研究(四)-----------桌面应用快捷方式的开发!
- Android Launcher桌面应用快捷方式的开发
- Android Launcher-----桌面应用快捷方式的开发!
- 【Android开发总结(1)】桌面快捷方式创建、删除、查询等方式
- 解析Android应用启动后自动创建桌面快捷方式的实现方法
- android 应用创建桌面快捷方式
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- Android开发两个例子:多点触控技术&桌面快捷方式
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式