Skip to content

Instantly share code, notes, and snippets.

@Sren-Hmkn
Created August 6, 2018 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sren-Hmkn/5cd071994794b9371fa7cc5d74ca06b0 to your computer and use it in GitHub Desktop.
Save Sren-Hmkn/5cd071994794b9371fa7cc5d74ca06b0 to your computer and use it in GitHub Desktop.
Ask for external storage read and write permissions
<!--
<uses-permission android:name="android.permission.CAMERA" />
Add the following two lines below the line above -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- ... -->
//...
//public class MainActivity extends AppCompatActivity {
static final Integer WRITE_EXST = 0x3;
static final Integer READ_EXST = 0x4;
// static final Integer CAMERA = 0x5;
//...
//...
// replace the whole ask-method with the following code:
public boolean ask() {
boolean answer = false;
if (askForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, WRITE_EXST)) {
if (askForPermission(Manifest.permission.READ_EXTERNAL_STORAGE, READ_EXST)) {
if (askForPermission(Manifest.permission.CAMERA, CAMERA)) {
answer = true;
}
}
} else {
answer = false;
}
return answer;
}
//...
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment