Android中生成快捷方式:
public CreateShut(Activity activity) {
// intent进行隐式跳转,到桌面创建快捷方式
Intent addIntent = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
//不允许重建
addIntent.putExtra("duplicate", false);
// 得到应用的名称
String title = activity.getResources().getString(R.string.app_name);
// 将应用的图标设置为Parceable类型
Parcelable icon = Intent.ShortcutIconResource.fromContext(
activity, R.drawable.ic_launcher);
// 点击图标之后的意图操作
Intent myIntent = new Intent(activity, MainActivity.class);
// 设置快捷方式的名称
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
// 设置快捷方式的图标
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
// 设置快捷方式的意图
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);
// 发送广播
activity.sendBroadcast(addIntent);
}需要注意:添加快捷方式需要添加权限<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
Android快捷方式创建
本文介绍如何在Android中创建应用程序的快捷方式。通过使用特定的Intent操作及设置必要的参数,可以实现在桌面上添加应用程序的快捷图标。此外,还需要在AndroidManifest.xml文件中声明相应的权限。
2351

被折叠的 条评论
为什么被折叠?



