美文网首页
Android6.0系统危险权限

Android6.0系统危险权限

作者: QM | 来源:发表于2017-04-13 11:20 被阅读0次

    危险权限

    GroupPermissionsandroid.permission-group.CALENDAR(日历)

    • android.permission.READ_CALENDAR
    • android.permission.WRITE_CALENDAR

    android.permission-group.CAMERA(相机)

    • android.permission.CAMERA

    android.permission-group.CONTACTS(联系人)

    • android.permission.READ_CONTACTS
    • android.permission.WRITE_CONTACTS
    • android.permission.GET_ACCOUNTS

    android.permission-group.LOCATION(定位)

    • android.permission.ACCESS_FINE_LOCATION
    • android.permission.ACCESS_COARSE_LOCATION

    android.permission-group.MICROPHONE(麦克风)

    • android.permission.RECORD_AUDIO

    android.permission-group.PHONE(电话)

    • android.permission.READ_PHONE_STATE
    • android.permission.CALL_PHONE
    • android.permission.READ_CALL_LOG
    • android.permission.WRITE_CALL_LOG
    • com.android.voicemail.permission.ADD_VOICEMAIL
    • android.permission.USE_SIP
    • android.permission.PROCESS_OUTGOING_CALLS

    android.permission-group.SENSORS(传感器)

    • android.permission.BODY_SENSORS

    android.permission-group.SMS(短信)

    • android.permission.SEND_SMS
    • android.permission.RECEIVE_SMS
    • android.permission.READ_SMS
    • android.permission.RECEIVE_WAP_PUSH
    • android.permission.RECEIVE_MMS
    • android.permission.READ_CELL_BROADCASTS

    android.permission-group.STORAGE(存储)

    • android.permission.READ_EXTERNAL_STORAGE
    • android.permission.WRITE_EXTERNAL_STORAGE

    代码

     private void checkPermission(String permission) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                int permissionCheck = ContextCompat.checkSelfPermission(MainActivity.this,
                        permission);
                //判断是否有权限
                if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
    
    //                if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
    //                        permission)) {
    //                    //前一次一倍拒绝,再次调起向用户额外解释权限的情况
    //                    Toast.makeText(this,"shouldShowRequestPermissionRationale",Toast.LENGTH_LONG).show();
    //                } else {
                        Toast.makeText(this,"没有权限,请求权限",Toast.LENGTH_LONG).show();
                        ActivityCompat.requestPermissions(MainActivity.this,
                                new String[]{permission},
                                PERMISSIONS_REQUEST);
    //                }
                }else {
                    Toast.makeText(this,"已有权限",Toast.LENGTH_LONG).show();
                }
            }else{
                Toast.makeText(this,"不是6.0系统",Toast.LENGTH_LONG).show();
            }
        }
    
        @Override
        public void onRequestPermissionsResult(int requestCode,
                                               String permissions[], int[] grantResults) {
            switch (requestCode) {
                case PERMISSIONS_REQUEST: {
                    if (grantResults.length > 0
                            && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
    
                        Toast.makeText(this,"允许权限",Toast.LENGTH_LONG).show();
    
                    } else {
                        showAppSettingsDialog();
                    }
                    return;
                }
            }
        }
    
        /**
         * 显示提示信息
         *
         */
        private void showAppSettingsDialog() {
    
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("权限提示");
            builder.setMessage("当前应用缺少必要权限。请点击\"设置\"-\"权限\"-打开所需权限。");
    
            // 拒绝, 退出应用
            builder.setNegativeButton("取消",
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });
    
            builder.setPositiveButton("设置",
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            startAppSettings();
                        }
                    });
    
            builder.setCancelable(false);
    
            builder.show();
        }
    
        /**
         *  启动应用的设置
         *
         * @since 2.5.0
         *
         */
        private void startAppSettings() {
            Intent intent = new Intent(
                    Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            intent.setData(Uri.parse("package:" + getPackageName()));
            startActivity(intent);
        }
    
    

    相关文章

      网友评论

          本文标题:Android6.0系统危险权限

          本文链接:https://www.haomeiwen.com/subject/thkbattx.html