Android添加桌面快捷方式的简单实现
2013-11-26 07:20
591 查看
核心代码如下:
Button bn = (Button) findViewById(R.id.bn); // 为按钮的单击事件添加监听器 bn.setOnClickListener(new OnClickListener() { @Override public void onClick(View source) { // 创建添加快捷方式的Intent Intent addIntent = new Intent( "com.android.launcher.action.INSTALL_SHORTCUT"); // ① String title = getResources().getString(R.string.title); // 设置快捷方式的标题 addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title); // ② // 加载快捷方式的图标 Parcelable icon = Intent.ShortcutIconResource.fromContext( AddShortcut.this, R.drawable.ic_launcher); // 设置快捷方式的图标 addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); // ② // 创建点击快捷方式后操作Intent,该处当点击创建的快捷方式后,再次启动该程序 Intent myIntent = new Intent(AddShortcut.this, AddShortcut.class); // 设置快捷方式对应的Intent addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent); // ② // 发送广播添加快捷方式 sendBroadcast(addIntent); // ③ } });
相关文章推荐
- Android编程实现向桌面添加快捷方式的方法
- Android桌面添加快捷方式的实现
- 如何把应用程序的快捷方式(shortcuts)添加到桌面——(开源项目apps-for-android中的AnyCut项目详解)
- Android在桌面添加两个快捷方式,如何区分从哪个入口进去的?
- Android 向桌面添加快捷方式
- Android实现向Launcher添加快捷方式的方法
- Android 向桌面添加删除快捷方式
- Android添加快捷方式(CutShort)到手机桌面
- Android添加快捷方式(Short)到手机桌面
- Android编程添加快捷方式(Short)到手机桌面的方法(含添加,删除及查询)
- Android 为程序添加桌面快捷方式
- Android中为你的应用程序添加桌面快捷方式
- Android Launcher开发(四)Launcher概述及简单添加和删除应用程序的快捷方式
- Android添加(创建)、删除及判断是否存在桌面快捷方式的方法
- Android添加快捷方式(Short)到手机桌面
- android桌面添加快捷方式之判断是否存在无效
- Android 向桌面添加快捷方式
- Android添加桌面快捷方式和删除桌面快捷方式
- Android 实现应用程序添加快捷方式