From cc95d3bdf32f8192b81f26c7e29ed751874db6ab Mon Sep 17 00:00:00 2001 From: Kevin Pelgrims Date: Fri, 16 Sep 2016 09:13:39 +0200 Subject: [PATCH 1/2] Remove storage permission for API 19 and up The getExternalFilesDir() directory does not require the WRITE_EXTERNAL_STORAGE permission as of API 19. --- demo/src/main/AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/src/main/AndroidManifest.xml b/demo/src/main/AndroidManifest.xml index d5aeda42..66de8375 100644 --- a/demo/src/main/AndroidManifest.xml +++ b/demo/src/main/AndroidManifest.xml @@ -14,7 +14,7 @@ - + From 246bb6bc9d3078d34b62a075a64f317f7e999ff7 Mon Sep 17 00:00:00 2001 From: Kevin Pelgrims Date: Fri, 16 Sep 2016 09:32:57 +0200 Subject: [PATCH 2/2] Remove all code related to requesting the storage permission We do not need to request this permission on API 19 and up to make use of getExternalFilesDir(). --- .../android/cameraview/demo/MainActivity.java | 30 ++----------------- demo/src/main/res/values/strings.xml | 2 -- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/demo/src/main/java/com/google/android/cameraview/demo/MainActivity.java b/demo/src/main/java/com/google/android/cameraview/demo/MainActivity.java index 821312aa..0e8c09da 100644 --- a/demo/src/main/java/com/google/android/cameraview/demo/MainActivity.java +++ b/demo/src/main/java/com/google/android/cameraview/demo/MainActivity.java @@ -55,7 +55,6 @@ public class MainActivity extends AppCompatActivity implements private static final String TAG = "MainActivity"; private static final int REQUEST_CAMERA_PERMISSION = 1; - private static final int REQUEST_STORAGE_PERMISSION = 2; private static final String FRAGMENT_DIALOG = "dialog"; @@ -88,24 +87,8 @@ public class MainActivity extends AppCompatActivity implements public void onClick(View v) { switch (v.getId()) { case R.id.take_picture: - if (ContextCompat.checkSelfPermission(MainActivity.this, - Manifest.permission.WRITE_EXTERNAL_STORAGE) - == PackageManager.PERMISSION_GRANTED) { - if (mCameraView != null) { - mCameraView.takePicture(); - } - } else if (ActivityCompat.shouldShowRequestPermissionRationale( - MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - ConfirmationDialogFragment - .newInstance(R.string.storage_permission_confirmation, - new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, - REQUEST_STORAGE_PERMISSION, - R.string.storage_permission_not_granted) - .show(getSupportFragmentManager(), FRAGMENT_DIALOG); - } else { - ActivityCompat.requestPermissions(MainActivity.this, - new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, - REQUEST_STORAGE_PERMISSION); + if (mCameraView != null) { + mCameraView.takePicture(); } break; } @@ -185,15 +168,6 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis } // No need to start camera here; it is handled by onResume break; - case REQUEST_STORAGE_PERMISSION: - if (permissions.length != 1 || grantResults.length != 1) { - throw new RuntimeException("Error on requesting storage permission."); - } - if (grantResults[0] != PackageManager.PERMISSION_GRANTED) { - Toast.makeText(this, R.string.storage_permission_not_granted, - Toast.LENGTH_SHORT).show(); - } - break; } } diff --git a/demo/src/main/res/values/strings.xml b/demo/src/main/res/values/strings.xml index fd9ac792..be269dd3 100644 --- a/demo/src/main/res/values/strings.xml +++ b/demo/src/main/res/values/strings.xml @@ -15,8 +15,6 @@ CameraView Demo This app demonstrates the usage of CameraView. In order to do that, it needs permission to access camera. Camera app cannot do anything without camera permission. - This app saves taken photos to external storage. - The app does not have permission to save a photo. Picture taken Switch flash Switch camera