package com.idt.os.gradviewtest; import android.Manifest; import android.content.pm.PackageManager; import android.os.Bundle; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); checkPermissions(); } private void checkPermissions(){ String[] permissions = { //需要申请的权限列表 Manifest.permission.RECORD_AUDIO, Manifest.permission.CALL_PHONE, Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.SEND_SMS, }; List<String> permissionDeniedList = new ArrayList<>(); for (String permission : permissions) { int permissionCheck = ContextCompat.checkSelfPermission(this, permission); if (permissionCheck != PackageManager.PERMISSION_GRANTED) { permissionDeniedList.add(permission); //加入要申请的权限列表 } } if (!permissionDeniedList.isEmpty()) { String[] deniedPermissions = permissionDeniedList.toArray(new String[permissionDeniedList.size()]); ActivityCompat.requestPermissions(this, deniedPermissions, 1); //请求列表中的权限 } } }
android 6.0以上动态权限申请
最新推荐文章于 2024-08-09 04:19:10 发布