避免多次生成快捷方式,存储一个boolean值判断是否已经生成快捷方式,生成快捷方式要添加权限<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/> private void initShorCut() { //给生成快捷方式的广播对应的意图添加action Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); //添加快捷方式图标 intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher)); //添加快捷方式名称 intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,"星空手机卫士"); //添加快捷方式意图,给开启的activity配置IntentFileter, Intent jump = new Intent(); jump.setAction("android.intent.action.Home"); jump.addCategory("android.intent.category.DEFAULT"); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,jump);
//发送广播隐式意图 sendBroadcast(intent);
SpUtil.writeBool(this,ConstValue.SHORT_CUT,true); }
|