android 6.0及以上版本手动申请隐私权限弹窗

需要在build.gradle里增加依赖:
//权限库
api 'com.yanzhenjie:permission:2.0.0-rc11'
/**
 * Android6.0和7.0需要主动拉起权限申请,获取手机imea码
 * @param activity
 */
public void getImea(final Activity activity){
    AndPermission.with(activity)
            .runtime()
            .permission(Permission.READ_PHONE_STATE)
            .onGranted(new Action>() {
                @SuppressLint("MissingPermission")
                @Override
                public void onAction(List data) {
                    TelephonyManager telephonyManager = (TelephonyManager) activity.getSystemService(TELEPHONY_SERVICE);
                    String imei = telephonyManager.getDeviceId();
                }
            })
            .onDenied(new Action>() {
                @Override
                public void onAction(List data) {
                }
            })
            .start();
}

你可能感兴趣的:(android 6.0及以上版本手动申请隐私权限弹窗)