Created
June 6, 2016 16:05
-
-
Save liangfeidotme/69c8851d39b7ba35b29d58b8d1245d88 to your computer and use it in GitHub Desktop.
Check whether the external storage is writable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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