首页 > 移动平台 > 详细

Android创建桌面快捷方式

时间:2014-01-22 09:30:50      阅读:502      评论:0      收藏:0      [点我收藏+]

在桌面上创建特定界面的快捷入口,icon和title根据请求参数命名。在网上收集的一些相关资 料,在使用intent发送广播的时候,一些型号的收集会有问题,如魅族MX,红米,以及华为,使用setClass和setComponent创建快捷 方式的时候不能正确生成快捷方式,有的快捷方式的会使用相应包下的APP名称命名,有的手机如魅族会应为包名冲突而无法创建快捷方式。解决的办法就是使用 setAction来创建Intent,然后可以在data/data/com.andoird.launcher/databases /launcher.db中查看桌面快捷方式的数据是否正确。以下是相关代码:

  Intent intent = new Intent("cn.example.action.SHORTCUT");
//自定义action
  
   intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
  
   Bundle bundle = new Bundle();
   bundle.putString("type", "default");
   intent.putExtras(bundle);
  
   //创建快捷方式的Intent
   Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
   //不允许重复创建
  shortcutintent.putExtra("duplicate", false);
   //需要现实的名称
  shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "快捷方式");
   //快捷图片
  Parcelable icon = Intent.ShortcutIconResource.fromContext(activity.getApplicationContext() , R.drawable.logo);
   shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
   //点击快捷图片,运行的程序主入口
  shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
   //发送广播。OK
   activity.sendBroadcast(shortcutintent);

然后在快捷启动对应的activity下加上intent-filter:
<intent-filter>
<action android:name="cn.kuwo.player.action.SHORTCUT" />
< /intent-filter>

这样就可以适应大多数机型

Android创建桌面快捷方式

原文:http://www.cnblogs.com/Free-Thinker/p/3529183.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!