This is my current (deprecated) method:
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
}
}
}
According to the android documentation https://developer.android.com/training/basics/intents/result I should use 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>() {
@Override
public void onActivityResult(Uri uri) {
// Handle the returned Uri
}
});
However I am struggling with replacing my method. Where do I insert my requestcode and my int array in the new method "registerForActivityResult()" ? Why do I need a "Uri" ?