版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35427437/article/details/81348415
private void createShowcut() {
//需要桌面生成的快捷图标
Intent intent=new Intent();
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
// 告诉桌面 快捷的图片
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory.decodeResource(getResources(),R.drawable.a));
//告诉桌面 快捷的名称
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,"手机卫士");
intent.putExtra("duplicate", false);
// 告诉桌面 快捷图标点击后的事件
Intent intentStart=new Intent();
intentStart.setAction("com.liwangjiang.safeadd");
intentStart.addCategory(Intent.CATEGORY_DEFAULT);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,intentStart);
sendBroadcast(intent);
}
权限
<!--生成桌面快捷键-->
<uses-permission android:name="android.permission.INSTALL_SHORTCUT"></uses-permission>
要打开的Activity
<activity android:name=".activity.HomeActivity">
<intent-filter>
<action android:name="com.liwangjiang.safeadd"></action>
<category android:name="android.intent.category.DEFAULT"></category>
</intent-filter>
</activity>