android创建桌面快捷方式(启动目标非项目的启动页)
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);
更多相关文章
- 小心XmlPullParser.netText()方法
- Android(安卓)后台发邮件
- mac Android(安卓)studio3.2版本安装+环境搭建
- android Java代码的启动
- LinearLayout 内部 挂件 居中
- Android——新手指引 指定View高光显示自定义控件
- AndroidManifest.xml的Service元素 android:process设置
- Android中的DownloadManager
- android页面全屏及状态栏和导航栏的(沉浸式)