content: package com.example.snippets.location;
  
  import android.Manifest;
  import android.os.Build;
  import android.os.Bundle;
  import androidx.activity.ComponentActivity;
  import androidx.activity.result.ActivityResultLauncher;
  import androidx.activity.result.contract.ActivityResultContracts;
  import java.util.Map;
  
  public class LocationPermissionsActivityJava extends ComponentActivity {
  
      // [START android_location_requestpermissions_java]
      private void requestPermissions() {
  
          ActivityResultLauncher<String[]> locationPermissionRequest =
                  registerForActivityResult(new ActivityResultContracts
                                  .RequestMultiplePermissions(), result -> {
  
                      Boolean fineLocationGranted = null;
                      Boolean coarseLocationGranted = null;
  
                      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                          fineLocationGranted = result.getOrDefault(
                                  Manifest.permission.ACCESS_FINE_LOCATION, false);
                          coarseLocationGranted = result.getOrDefault(
                                  Manifest.permission.ACCESS_COARSE_LOCATION,false);
                      }
  
                      if (fineLocationGranted != null && fineLocationGranted) {
                          // Precise location access granted.
                      } else if (coarseLocationGranted != null && coarseLocationGranted) {
                          // Only approximate location access granted.
                      } else {
                          // No location access granted.
                      }
                  }
              );
  
          // ...
  
          // Before you perform the actual permission request, check whether your app
          // already has the permissions, and whether your app needs to show a permission
          // rationale dialog. For more details, see Request permissions.
          locationPermissionRequest.launch(new String[] {
                  Manifest.permission.ACCESS_FINE_LOCATION,
                  Manifest.permission.ACCESS_COARSE_LOCATION
          });
      }
      // [END android_location_requestpermissions_java]
  }