【发布时间】:2017-11-30 19:13:15
【问题描述】:
这是我的代码
主目录
<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.+'
获取此类空图或空图
【问题讨论】:
-
您似乎从未为
imageUri设置过值。 -
@CommonsWare 。我没有得到。请告诉我这段代码有什么问题?
-
使用前检查 imageUri==null。
-
Getting this kind of null image or Empty image。你的意思是?请准确。 Null 和empty 是不一样的。告诉我们你得到了什么。 -
mCropImageView.。那是什么?
标签: android image android-fileprovider