我應該在類Application中的運行時應用權限嗎? 例如:內部類擴展應用我寫了一些代碼,而不是我在另一個類中寫道:在Android中擴展類應用程序?
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(PhotoActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(PhotoActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(PhotoActivity.this,
Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(PhotoActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA},
Constants.MY_PERMISSIONS_REQUEST_ACCESS_STORAGE);
}
}
P/S:對不起,我的英語:(