安卓调用系统相机拍照的几个步骤,同时解决版本兼容问题

1.onCreate调用
// android 7.0系统解决拍照的问题
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
builder.detectFileUriExposure();
 
  
2.
private final String[] PERMISSIONS = new String[] {
        Manifest.permission.WRITE_EXTERNAL_STORAGE,
        Manifest.permission.READ_EXTERNAL_STORAGE,
        Manifest.permission.CAMERA,
};
 
  
3.
 
  
public static final String FALNS_PLANTE_BASE_PATH = Environment.getExternalStorageDirectory().getPath() + File.separator + "FansPlante/";

intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.addCategory("android.intent.category.DEFAULT");
File file = new File(Constants.FALNS_PLANTE_BASE_PATH + "/takepicture.jpg");
Uri uri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
mActivity.startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE);
 
  
 
  
4.
public void onActivityResult(int requestCode, int resultCode, Intent resultIt) {
    if (resultCode != Activity.RESULT_OK) {
        return;
    }

    Log.e(TAG, "onActivityResult: ====>>" + requestCode);
}

你可能感兴趣的:(android)