189 8069 5689

Android拨打电话 安卓拨打电话权限

  
    
    
    
 // 检查是否获得了权限(Android6.0运行时权限)
                if (ContextCompat.checkSelfPermission(MainActivity.this,
                        Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED){                    // 没有获得授权,申请授权
                    if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
                            Manifest.permission.CALL_PHONE)) {                        // 返回值://                          如果app之前请求过该权限,被用户拒绝, 这个方法就会返回true.//                          如果用户之前拒绝权限的时候勾选了对话框中”Don’t ask again”的选项,那么这个方法会返回false.//                          如果设备策略禁止应用拥有这条权限, 这个方法也返回false.
                        // 弹窗需要解释为何需要该权限,再次请求授权
                        Toast.makeText(MainActivity.this, "请授权!", Toast.LENGTH_LONG).show();                        // 帮跳转到该应用的设置界面,让用户手动授权
                        Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                        Uri uri = Uri.fromParts("package", getPackageName(), null);
                        intent.setData(uri);
                        startActivity(intent);
                    }else{                        // 不需要解释为何需要该权限,直接请求授权
                        ActivityCompat.requestPermissions(MainActivity.this,                                new String[]{Manifest.permission.CALL_PHONE},
                                MY_PERMISSIONS_REQUEST_CALL_PHONE);
                    }
                }else {                    // 已经获得授权,可以打电话
                 
                 

//用intent启动拨打电话
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + mobile));
startActivity(intent);
                }

网站题目:Android拨打电话 安卓拨打电话权限
本文链接:http://cdxtjz.com/article/johcep.html

其他资讯