记又一次被 Android 动态权限请求坑的经历
被动态权限获取安排的明明白白。
谁知道那家伙用的是 5.0 的系统 。。。所以说如果用了 ContextCompat 和 ActivityCompat 就不需要自己再去判断一次版本号了…
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
- if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
- ActivityCompat.requestPermissions(this,
- new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
- READ_REQUEST_CODE);
- } else {
- dosth();
- }
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
+ ActivityCompat.requestPermissions(this,
+ new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
+ READ_REQUEST_CODE);
+ } else {
+ dosth();
+ }