这是我的代码
MAINIFEST
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
provider_path.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
此处检查Naugat是否执行此操作
if (haswritePermission == PackageManager.PERMISSION_GRANTED && hasWriteContactsPermission == PackageManager.PERMISSION_GRANTED) {
++imageId;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
String imageFilePath = Environment.getExternalStorageDirectory().toString() + "/Images/Profile/profile.jpg";
File imageFile = new File(imageFilePath);
imageUri = FileProvider.getUriForFile(MainActivity.this, BuildConfig.APPLICATION_ID + ".provider", imageFile);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, PICK_FROM_CAMERA);
}
}
onActivityResult
public void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case PICK_FROM_CAMERA:
mCropImageView.setImageUriAsync(imageUri);
[crop_dialog][1].show();
break;
}
}
}
裁剪图片我正在使用此资料库
compile 'com.theartofdev.edmodo:android-image-cropper:2.5.+'
获取此类空图像或空图像
答案 0 :(得分:0)
I just change code for Nougat .add separate case for nougat
**for less than M**
case PICK_FROM_CAMERA:
mCropImageView.setImageUriAsync(imageUri);
path=getRealPathFromURI(imageUri);
Bitmap bitmap=rotateBitmapOrientation(path);
mCropImageView.setImageBitmap(bitmap);
crop_dialog.show();
break;
**for Nougat **
case CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE:
mCropImageView.setImageUriAsync(imageUri);
selectedImage);
crop_dialog.show();
break;