From cdbe3aa29eca0e0bfd16d302d376b30eee860c41 Mon Sep 17 00:00:00 2001 From: Chintan Date: Sun, 22 Oct 2017 23:00:09 +0530 Subject: [PATCH] Uri Expose Exception Resolved QR Photo File deleted after reading it --- QRCode/app/src/main/AndroidManifest.xml | 31 +++++++++++++------ .../mobile/vision/qrcode/MainActivity.java | 18 ++++++++++- .../app/src/main/res/xml/provider_paths.xml | 4 +++ 3 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 QRCode/app/src/main/res/xml/provider_paths.xml diff --git a/QRCode/app/src/main/AndroidManifest.xml b/QRCode/app/src/main/AndroidManifest.xml index 2fe9e85..f5da953 100644 --- a/QRCode/app/src/main/AndroidManifest.xml +++ b/QRCode/app/src/main/AndroidManifest.xml @@ -1,26 +1,39 @@ - + - + android:required="true" /> + + + + + + + - + android:value="barcode" /> + - + - + diff --git a/QRCode/app/src/main/java/com/truiton/mobile/vision/qrcode/MainActivity.java b/QRCode/app/src/main/java/com/truiton/mobile/vision/qrcode/MainActivity.java index 1cb05c4..0e9e988 100644 --- a/QRCode/app/src/main/java/com/truiton/mobile/vision/qrcode/MainActivity.java +++ b/QRCode/app/src/main/java/com/truiton/mobile/vision/qrcode/MainActivity.java @@ -7,11 +7,13 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; +import android.support.v4.content.FileProvider; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.util.SparseArray; @@ -134,6 +136,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { break; } } + if (barcodes.size() == 0) { scanResults.setText("Scan Failed: Found nothing to scan"); } @@ -145,13 +148,26 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { .show(); Log.e(LOG_TAG, e.toString()); } + /*Deleting the photo stored after clicking the picture*/ + File photo = new File(Environment.getExternalStorageDirectory(), "picture.jpg"); + if (photo.exists()) { + photo.delete(); + } + } } private void takePicture() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File photo = new File(Environment.getExternalStorageDirectory(), "picture.jpg"); - imageUri = Uri.fromFile(photo); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + imageUri = FileProvider.getUriForFile(getApplicationContext(), + getApplicationContext() + .getPackageName() + ".provider", photo); + } else { + imageUri = Uri.fromFile(photo); + } + intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); startActivityForResult(intent, PHOTO_REQUEST); } diff --git a/QRCode/app/src/main/res/xml/provider_paths.xml b/QRCode/app/src/main/res/xml/provider_paths.xml new file mode 100644 index 0000000..ffa74ab --- /dev/null +++ b/QRCode/app/src/main/res/xml/provider_paths.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file