首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android直接在圆桌面生成快捷方式

2012-06-29 
android直接在桌面生成快捷方式? ??Android在桌面上生成快捷方式有两种情况,一种是直接在桌面直接生成一

android直接在桌面生成快捷方式

? ??Android在桌面上生成快捷方式有两种情况,一种是直接在桌面直接生成;一种是长按桌面,在弹出的快捷菜单中生成。这是讨论第一种,直接在桌面生成。

? ??这种是通过广播(Broadcast)的形式向Luncher发送请求生成快捷方式的。

 首先在activity中设置:

? ? 然后添加权限:

?

  下面就是代码层的实现:

  在activity中创建一个创建快捷方式的方法:addShortCut();

public boolean addShortcut() {// 创建快捷方式的IntentIntent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");// 不允许重复创建shortcutintent.putExtra("duplicate", false);// 快捷方式名称shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME,getString(R.string.shortcutname));// 快捷方式图片Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.shortcut);shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// 点击快捷图片,运行的程序主入口shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext(), Activity01.class));// 发送广播。OKsendBroadcast(shortcutintent);return true;}
?

热点排行