好吧,我有在如下面的代碼和警告: Android Studio添加權限檢查錯誤?
當我同意添加此類檢查,AS插入下面的代碼:
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return TODO;
}
而我只是想知道,爲什麼AND運算符正在使用?
如果用戶只拒絕上面的權限之一,那麼這樣的檢查將不起作用,就像我一樣。
還是我想念什麼?
好吧,所以Android Studio添加的權限檢查是錯誤的?在這種情況下,應該有OR運算符而不是AND。 –