Skip to content

Commit

Permalink
Merge pull request google#16 from kevinpelgrims/storage_permission
Browse files Browse the repository at this point in the history
Storage permission
  • Loading branch information
yaraki authored Sep 16, 2016
2 parents 3942c49 + 914ecde commit c471578
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 31 deletions.
2 changes: 1 addition & 1 deletion demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<manifest package="com.google.android.cameraview.demo"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18"/>

<application
android:allowBackup="true"
Expand Down
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 c471578

Please sign in to comment.