1.清单文件
动态和静态添加权限都需要配置清单文件! <uses-permission android:name="android.permission.CAMERA"/>
2.相机的点击事件
//设置相机的点击事件 img.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(Build.VERSION.SDK_INT>=23){ ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.CAMERA},0); int permission = ContextCompat.checkSelfPermission(MainActivity.this.getApplicationContext(), Manifest.permission.CAMERA); if(permission==PackageManager.PERMISSION_GRANTED){ //如果有了相机的权限就调用相机 startCamera(); }else { AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this); builder.setTitle("提示"); builder.setMessage("是否开启相机权限"); builder.setPositiveButton("是", new DialogInterface.OnClickLi