91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

android 6.0 權限授權方法

發布時間:2020-10-21 05:47:05 來源:腳本之家 閱讀:119 作者:hhbbeijing 欄目:移動開發

這里介紹兩種方式,如下:

一、逐次

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;
  }
 }
}

二、全部

private void requestPermission() {

 List<String> permissionsNeeded = new ArrayList<String>();

 if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)== PackageManager.PERMISSION_DENIED) {
  permissionsNeeded.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
 }
 if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
  permissionsNeeded.add(Manifest.permission.READ_EXTERNAL_STORAGE);

 }
 if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_DENIED) {
  permissionsNeeded.add(Manifest.permission.CAMERA);

 }
 if(permissionsNeeded.size()>0){
  ActivityCompat.requestPermissions(this, permissionsNeeded.toArray(new String[permissionsNeeded.size()]), 1);
 }
}

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

     } else {
      dialog();
     }
    } else {
     dialog();
    }
   } else {
    dialog();
   }
   break;
  }
 }
}

以上這篇android 6.0 權限授權方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

县级市| 托克托县| 罗城| 贵定县| 建平县| 吴旗县| 固安县| 海宁市| 枣庄市| 万源市| 沈阳市| 金堂县| 申扎县| 合水县| 定远县| 娱乐| 象山县| 武功县| 洱源县| 德庆县| 锡林郭勒盟| 简阳市| 綦江县| 普格县| 修武县| 涿州市| 屏南县| 绍兴市| 措勤县| 云阳县| 若尔盖县| 阿坝县| 休宁县| 淮安市| 丹东市| 崇礼县| 汽车| 黄骅市| 侯马市| 镇康县| 忻城县|