android创建桌面图标

来源:互联网 发布:百战天下坐骑进阶数据 编辑:程序博客网 时间:2024/05/01 19:32
private void setDeskShortCut() {boolean installedshortcut = sp.getBoolean("installedshortcut", false);if (installedshortcut) {return;}//创建一个快捷方式的意图Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,       //快捷方式的名称getString(R.string.app_name));intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.mobilesafe_logo_s));   //快捷方式的图标//设置点击这个快捷方式,打开哪个activityIntent openMS = new Intent("com.hy.test.activities.home");openMS.addCategory("android.intent.category.DEFAULT");intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, openMS);  //快捷方式的打开界面sendBroadcast(intent); //发送一个广播Editor editor = sp.edit();editor.putBoolean("installedshortcut", true);editor.commit();}


!!!添加权限:com.android.launcher.permission.INSTALL_SHORTCUT

0 0
原创粉丝点击