Skip to content

Instantly share code, notes, and snippets.

@liangfeidotme
Created June 6, 2016 16:05
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 liangfeidotme/69c8851d39b7ba35b29d58b8d1245d88 to your computer and use it in GitHub Desktop.
Save liangfeidotme/69c8851d39b7ba35b29d58b8d1245d88 to your computer and use it in GitHub Desktop.
Check whether the external storage is writable.
@Override
public boolean isLeakStorageWritable() {
if (!hasStoragePermission()) {
return false;
}
String state = Environment.getExternalStorageState();
return Environment.MEDIA_MOUNTED.equals(state);
}
@TargetApi(M)
private boolean hasStoragePermission() {
if (SDK_INT < M) {
return true;
}
return context.checkSelfPermission(WRITE_EXTERNAL_STORAGE) == PERMISSION_GRANTED;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment