Skip to content

Instantly share code, notes, and snippets.

@rogergcc
Last active October 7, 2023 16:16
Show Gist options
  • Save rogergcc/f619cfadfb1a4d0d02cfa0f79b7c8c66 to your computer and use it in GitHub Desktop.
Save rogergcc/f619cfadfb1a4d0d02cfa0f79b7c8c66 to your computer and use it in GitHub Desktop.
import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import androidx.core.app.ActivityCompat;
/**
* Created on septiembre.
* year 2023 .
*/
public class PermissionUtil {
public static final int LOCATION_PERMISSION_REQUEST_CODE = 1;
public static boolean checkLocationPermission(Activity activity) {
int permissionFineLocation = ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION);
int permissionCoarseLocation = ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION);
return permissionFineLocation == PackageManager.PERMISSION_GRANTED && permissionCoarseLocation == PackageManager.PERMISSION_GRANTED;
}
public static void requestLocationPermission(Activity activity) {
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, LOCATION_PERMISSION_REQUEST_CODE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment