From 8ab77abb6d63dd84f2ba27df0819672fc01b502f Mon Sep 17 00:00:00 2001 From: lingxiaopua <1083514716@qq.com> Date: Sat, 30 Mar 2019 22:47:15 +0800 Subject: [PATCH] update use system camera example with androidx --- .../camera/lingxiao/camerademo/SystemCameraActivity.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/camera/lingxiao/camerademo/SystemCameraActivity.java b/app/src/main/java/com/camera/lingxiao/camerademo/SystemCameraActivity.java index ca86b42..5d4009a 100644 --- a/app/src/main/java/com/camera/lingxiao/camerademo/SystemCameraActivity.java +++ b/app/src/main/java/com/camera/lingxiao/camerademo/SystemCameraActivity.java @@ -2,6 +2,7 @@ import android.app.Activity; import android.content.Intent; +import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; @@ -59,7 +60,8 @@ public void onClick(View v) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //如果是7.0以上,使用FileProvider,否则会报错 intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - Uri imgUri = FileProvider.getUriForFile(getApplicationContext(), "com.camera.lingxiao.camerademo.fileProvider", it); + String authority = getApplicationInfo().packageName + ".fileProvider"; + Uri imgUri = FileProvider.getUriForFile(getApplicationContext(), authority, it); intent.putExtra(MediaStore.EXTRA_OUTPUT, imgUri); //设置拍照后图片保存的位置 } else { intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(it)); //设置拍照后图片保存的位置 @@ -77,8 +79,9 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { if (requestCode == 200) { Toast.makeText(this, "拍照成功", Toast.LENGTH_SHORT).show(); + String authority = getApplicationInfo().packageName + ".fileProvider"; Uri imgUri = FileProvider.getUriForFile(getApplicationContext(), - "com.camera.lingxiao.camerademo.fileProvider", it); + authority, it); gotoCrop(imgUri); } else if (requestCode == 201) { Bitmap bitmap = BitmapFactory.decodeFile(it.getAbsolutePath());