Skip to content

Commit

Permalink
Remove all code related to requesting the storage permission
Browse files Browse the repository at this point in the history
We do not need to request this permission on API 19 and up to make
use of getExternalFilesDir().
  • Loading branch information
kevinpelgrims committed Sep 16, 2016
1 parent cc95d3b commit 246bb6b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}

Expand Down
2 changes: 0 additions & 2 deletions demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
<string name="app_name">CameraView Demo</string>
<string name="camera_permission_confirmation">This app demonstrates the usage of CameraView. In order to do that, it needs permission to access camera.</string>
<string name="camera_permission_not_granted">Camera app cannot do anything without camera permission.</string>
<string name="storage_permission_confirmation">This app saves taken photos to external storage.</string>
<string name="storage_permission_not_granted">The app does not have permission to save a photo.</string>
<string name="picture_taken">Picture taken</string>
<string name="switch_flash">Switch flash</string>
<string name="switch_camera">Switch camera</string>
Expand Down

0 comments on commit 246bb6b

Please sign in to comment.