首页 > 其他 > 详细

桌面快捷方式

时间:2014-04-14 21:01:58      阅读:616      评论:0      收藏:0      [点我收藏+]

  在做app过程中,有可能在设置里面有设置添加桌面快加方式的功能。下面就添加shortcut 研究下

  首先判断一下桌面是否已经添加了快捷方式:

判断api版本 以2.2版本的api 为判断标准

通过ContentProvier查询快捷方式数据

String url="";

  if(android.os.Build.VERSION.SDK_INT<8){

    url="content://com.android.launcer.settings/favorites?notify=true";

}else{

  url="content://com.android.launcer.settings2/favorites?notify=true";

}

 ContentResolver  resolver=context.getContentResolver();  //内容解析器

Cursor cursor=resolver.query(Uri.parse(url),null,"title=?",new String[]{context.getString(R.string.app_name)},null);

if(cursor!=null&&cursor.moveToFirst()){

      cursor.close();

}

判定完毕符合条件的话执行addshortcut方法

String ACTION_ADD_SHORTCUT="com.android.launcer.action.INSTALL_SHORTCUT";  //Intent  添加快捷方式 的action值

//也可以调用Manifest 类里面的静态低层内部类permission里的常量 INSTALL_SHORTCUT   但是api大于等于9

Intent intent=new Intent(ACTION_ADD_SHORTCUT);

ShortcutIconResource icon=Intent.ShortcutIconResource.fromContext(context,R.drawable.icon);  //获取快件方式图片

intent.putExtra("duplicate",false);//不允许重复创建

intent.putExtra(Intent.EXTRA_SHORTCUT_ICON.RESOURCE,icon);

intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,context.getString(R.string.app_name));

//设置切入的主activity

intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,new Intent(getApplicationContext(),AppMainActivity.class));

//或者使用component 

Intent maincutintent=new Intent();

maincutintent.setComponent(new ComponentName(context.getPackageName(),context.getPackageName()+".AppMainActivity"));

intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,maincutintent);

context.sendBoradcast(intent);  //发送广播


删除快件方式使用 

action 只为  com.android.launcher.action.UNINSTALL_SHORTCUT  的intent执行任务





  



桌面快捷方式,布布扣,bubuko.com

桌面快捷方式

原文:http://blog.csdn.net/duty_is_codeing/article/details/23662841

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