1.布局文件中,目标Activity加入以下filter

    <intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

2.通过发送广播的方式调用

      Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.seckill));//设置快捷图标的名字
shortcut.putExtra("duplicate", false);//设置是否重复创建
Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setClass(getActivity(), ProductListActivity.class);//设置第一个页面
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(getActivity(), R.drawable.wx_friend_non);//设置快捷图标的资源
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
getActivity().sendBroadcast(shortcut);

更多相关文章

  1. 小心XmlPullParser.netText()方法
  2. Android(安卓)后台发邮件
  3. mac Android(安卓)studio3.2版本安装+环境搭建
  4. android Java代码的启动
  5. LinearLayout 内部 挂件 居中
  6. Android——新手指引 指定View高光显示自定义控件
  7. AndroidManifest.xml的Service元素 android:process设置
  8. Android中的DownloadManager
  9. android页面全屏及状态栏和导航栏的(沉浸式)

随机推荐

  1. android的DALVIK虚拟机简介
  2. Android之Http通信——3.Android(安卓)HT
  3. GVoice腾讯游戏语音Android(安卓)Studio
  4. Android(安卓)Activity管理之Activity栈
  5. 游走Android系列之APK文件的反编译、修改
  6. Android检测手机中存储卡及剩余空间大小
  7. 深入浅出谈Android(安卓)几种布局方式
  8. R cannot be resolved to a variable
  9. Android绘图机制(五)自定义控件的官方实例
  10. Google android初级开发之 : android 模