这是我当前(已弃用)的方法:
int LOCATION_REQUEST_CODE = 10001;
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
if (requestCode == LOCATION_REQUEST_CODE) {
//Permission granted
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
checkSettingsAndStartLocationUpdates();
} else {
//DO SOMETHING - Permission not granted
}
}
}
Run Code Online (Sandbox Code Playgroud)
根据android文档https://developer.android.com/training/basics/intents/result我应该使用registerForActivityResult():
// GetContent creates an ActivityResultLauncher<String> to allow you to pass
// in the mime type you'd like to allow the user to select
ActivityResultLauncher<String> mGetContent = registerForActivityResult(new GetContent(),
new ActivityResultCallback<Uri>() { …Run Code Online (Sandbox Code Playgroud)