如图
import android.support.v4.app.ActivityCompat;import android.support.v4.content.ContextCompat;
代码如下
private void requestPermission(String permission){ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ if (ContextCompat.checkSelfPermission(BookListActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(BookListActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_READ_CONTACTS); } } }
android-support-v4.jar 是什么版本的checkSelfPermission方法在23.0.0及后续版本中才有