android6.0权限授权方法-创新互联

这里介绍两种方式,如下:

创新互联专注于古县网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供古县营销型网站建设,古县网站制作、古县网页设计、古县网站官网定制、重庆小程序开发服务,打造古县网络公司原创品牌,更为您提供古县网站排名全网营销落地服务。

一、逐次

private static final int PERMISSION_READ_EXTERNAL_STORAGE = 101;
private static final int PERMISSION_WRITE_EXTERNAL_STORAGE = 102;
private static final int PERMISSION_CAMERA = 103;
private void requestPermission() {
 if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)== PackageManager.PERMISSION_DENIED) {
  ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_WRITE_EXTERNAL_STORAGE);
 }
 if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
  ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_READ_EXTERNAL_STORAGE);
 }
 if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_DENIED) {
  ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, PERMISSION_CAMERA);
 }
}


@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int []grantResults) {
 switch (requestCode) {
  case PERMISSION_CAMERA: {
   if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {


   } else {
    Toast.makeText(this, "没有摄像头权限我什么都做不了哦!", Toast.LENGTH_LONG).show();
   }
   break;
  }
  case PERMISSION_READ_EXTERNAL_STORAGE: {
   if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {


   } else {
    Toast.makeText(this, "请打开存储读写权限,确保APP正常运行", Toast.LENGTH_LONG).show();;
   }
   break;
  }
  case PERMISSION_WRITE_EXTERNAL_STORAGE: {
   if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {


   } else {
    Toast.makeText(this, "请打开存储读写权限,确保APP正常运行", Toast.LENGTH_LONG).show();;
   }
   break;
  }
 }
}

新闻名称:android6.0权限授权方法-创新互联
文章分享:https://www.cdcxhl.com/article18/dsdjdp.html

成都网站建设公司_创新互联,为您提供关键词优化移动网站建设微信小程序虚拟主机App设计定制开发

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

手机网站建设