android添加快捷方式
16lz
2021-01-25
1.在清单文件里添加
<!-- 定义添加到桌面Launcher中 -->这个是放在主activity里边<intent-filter><action android:name="android.intent.action.CREATE_SHORTCUT" /></intent-filter>2.指定添加安装快捷方式的权限<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
在代码中添加:
// 创建添加快捷方式的IntentIntent addIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");String title = getResources().getString(R.string.app_name);// 加载快捷方式的图标Parcelable icon = Intent.ShortcutIconResource.fromContext(MainActivity.this, R.drawable.ic_launcher);// 创建点击快捷方式后操作Intent,该处当点击创建的快捷方式后,再次启动该程序Intent myIntent = new Intent(MainActivity.this,MainActivity.class);// 设置快捷方式的标题addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);// 设置快捷方式的图标addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// 设置快捷方式对应的IntentaddIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);// 发送广播添加快捷方式sendBroadcast(addIntent);
更多相关文章
- Android(安卓)app ERR_UNKNOWN_URL_SCHEME
- Android内存泄漏排查利器LeakCanary
- Android-- 抽屉式公告
- android 5.0以上通知栏、状态栏图标变成白色
- linux下如何为刚安装好的Eclipse在桌面建一个启动图标???(QtCreator
- Android屏幕大小适配问题解决
- Android(安卓)webview-tips
- Android之ToolBar项目封装,踩坑过河
- android 10 手机无法预览到图片, 加载图片, 无法显示图片内容问