Android:创建快捷方式
2012-03-19 20:00
176 查看
Java代码
/** * 创建快捷方式到Shortcut列表<br> * 关联程序的<intent-filter>中添加:<actionandroid:name="android.intent.action.CREATE_SHORTCUT"/> */ private void addShortcutToOptions() { Intent shortcut = new Intent(Intent.ACTION_CREATE_SHORTCUT); // 不允许重建 shortcut.putExtra("duplicate", false); // 设置名字 shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, this.getString(R.string.app_name)); // 设置图标 shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher)); // 设置意图和快捷方式关联的程序 shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this, this.getClass())); // 发送消息队列 setResult(RESULT_OK, shortcut); } /** * 添加快捷方式到桌面 要点: * 1.给Intent指定action="com.android.launcher.INSTALL_SHORTCUT" * 2.给定义为Intent.EXTRA_SHORTCUT_INENT的Intent设置与安装时一致的action(必须要有) * 3.添加权限:com.android.launcher.permission.INSTALL_SHORTCUT */ private void addShortcutToDesktop() { Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); // 不允许重建 shortcut.putExtra("duplicate", false); // 设置名字 shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,this.getString(R.string.app_name)); // 设置图标 shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher)); // 设置意图和快捷方式关联程序 shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,new Intent(this, this.getClass()).setAction(Intent.ACTION_MAIN)); // 发送消息 sendBroadcast(shortcut); } /** * 添加权限:<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/> * */ private boolean hasInstallShortcut() { boolean hasInstall = false; final String AUTHORITY = "com.android.launcher.settings"; Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/favorites?notify=true"); Cursor cursor = this.getContentResolver().query(CONTENT_URI, new String[] { "title", "iconResource" }, "title=?", new String[] { this.getString(R.string.app_name) }, null); if (cursor != null && cursor.getCount() > 0) { hasInstall = true; } return hasInstall; }
相关文章推荐
- android 创建快捷方式的两种途径
- 关于android创建快捷方式会启动两个应用的问题(二)
- android 创建快捷方式
- android 创建桌面快捷方式 、插件
- android 2.3 shortCut快捷方式创建与删除的问题
- Android创建桌面快捷方式两种方法
- 总结:android 创建快捷方式的两种方式+判断是否已经创建+删除快捷方式
- Android创建和删除桌面快捷方式
- android 创建快捷方式
- [Android] Android应用启动后自动创建桌面快捷方式
- Android应用启动后自动创建桌面快捷方式
- Android 创建桌面快捷方式
- Android创建桌面快捷方式
- android创建快捷方式来打开应用中特定的Activity
- Android为应用创建快捷方式
- Android笔记:Android应用启动后自动创建桌面快捷方式
- [Android]为指定的应用创建桌面快捷方式
- Android_如何创建桌面快捷方式
- Android创建快捷方式实现
- android应用内为某个Activity创建快捷方式后按home键的问题