1. 程式人生 > >Android6.0手動加許可權

Android6.0手動加許可權

private static final int REQUEST_EXTERNAL_STORAGE = 0;
private static final int REQUEST_CAMERA = 2;
private static String[] PERMISSIONS_STORAGE = {
        Manifest.permission.READ_EXTERNAL_STORAGE,
        Manifest.permission.WRITE_EXTERNAL_STORAGE,

Manifest.permission.CAMERA};

// TODO: 2016/10/6 選擇圖片前,為6.0動態新增許可權
int permission = ActivityCompat.checkSelfPermission(SubmitCompleteActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE); int permission2 = ActivityCompat.checkSelfPermission(SubmitCompleteActivity.this, Manifest.permission.CAMERA); if (permission != PackageManager.PERMISSION_GRANTED) { // 沒有許可權,加許可權
ActivityCompat.requestPermissions(SubmitCompleteActivity.this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE); } else if (permission2 != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(SubmitCompleteActivity.this, PERMISSIONS_STORAGE, REQUEST_CAMERA); } else
{//加了許可權 //開啟相簿頁面 PhotoPicker.builder() .setPhotoCount(photoNumber) .setGridColumnCount(PHOTO_MAX_ROW_NUM) .start(SubmitCompleteActivity.this); }