android 创建添加快捷方式
16lz
2022-04-23
// 创建添加快捷方式的Intent
Intent addIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
String title = getResources().getString(R.string.app_name);
// 加载快捷方式的图标
Parcelable icon = Intent.ShortcutIconResource.fromContext(WelcomeActivity.this, R.drawable.icon);
// 创建点击快捷方式后操作Intent,该处当点击创建的快捷方式后,再次启动该程序
Intent myIntent = new Intent(WelcomeActivity.this,WelcomeActivity.class);
// 设置快捷方式的标题
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
// 设置快捷方式的图标
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
// 设置快捷方式对应的Intent
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);
// 发送广播添加快捷方式
sendBroadcast(addIntent);
Intent addIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
String title = getResources().getString(R.string.app_name);
// 加载快捷方式的图标
Parcelable icon = Intent.ShortcutIconResource.fromContext(WelcomeActivity.this, R.drawable.icon);
// 创建点击快捷方式后操作Intent,该处当点击创建的快捷方式后,再次启动该程序
Intent myIntent = new Intent(WelcomeActivity.this,WelcomeActivity.class);
// 设置快捷方式的标题
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
// 设置快捷方式的图标
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
// 设置快捷方式对应的Intent
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);
// 发送广播添加快捷方式
sendBroadcast(addIntent);
更多相关文章
- Android4.1 Rotation 小结
- Android(安卓)EditText达到SearchView的效果
- Android(安卓)Studio设置类代码模板
- android通过反射来获取系统属性SystemProperties
- android 自带的下拉刷新控件,含Demo(SwipeRefreshLayout控件)
- Android创建应用程序快捷方式(shortcut)
- Android初级教程调用手机拍照与摄像功能
- Android获取高清app图标代码分享
- Android(安卓)4.0 创建AVD报错