能解釋我plaese我應該怎麼解釋給用戶權限棉花糖權限和解釋
我Camera2API工作,我根據谷歌碼頭我應該執行的代碼,例如片斷問permishion dinamicly
private void openCamera(int width, int height) {
setUpCameraOutputs(width, height);
CameraHelper.configureTransform(width, height, textureView, previewSize, getActivity());
CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
try {
if (!cameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
throw new RuntimeException("Time out waiting to lock camera opening.");
}
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) !=
PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(
getActivity(), new String[]{android.Manifest.permission.CAMERA},
MY_PERMISSIONS_REQUEST);
// MY_PERMISSIONS_REQUEST is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted while trying to lock camera opening.", e);
}
}
檢查如果用戶之前
拒絕權限有方法,該方法返回的虛假
shouldShowRequestPermissionRationale();
01真
,並根據谷歌
,如果應用程序已請求此權限以前與用戶拒絕了這一要求該方法返回true。
如果我沒有理解這個方法裏面執行根據正確谷歌評論
//顯示說明用戶異步 - 不阻止
//這個線程等待用戶的迴應!用戶
//看到說明後,請再次嘗試請求許可。
最後例如用戶拒絕下一次我之前的許可,當他去我的屏幕,攝像頭的應用程序應該創建我castom彈出與解釋:「如果你想繼續請同意這個permishion」和示例用戶同意這次,並且我應該根據此回憶該方法
//看到說明,再試請求許可。
但這種方法
shouldShowRequestPermissionRationale();
回我true
再次,因爲它不知道用戶的意圖許可同意。
請問您能解釋一下我如何正確使用它?也許你有例子嗎?
試試這個,可能是工作http://stackoverflow.com/a/41221852/5488468 –