From 8a98df785b354707839293d49695d7fe3f007c26 Mon Sep 17 00:00:00 2001 From: Simonas Date: Sun, 5 Jan 2020 17:34:37 +0200 Subject: [PATCH] Check for location permissions The permission check should be handled in the code. --- app/src/main/java/com/lt/lrmd/lhfa/GPSTracker.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/lt/lrmd/lhfa/GPSTracker.java b/app/src/main/java/com/lt/lrmd/lhfa/GPSTracker.java index c3f81f6..ea777d4 100644 --- a/app/src/main/java/com/lt/lrmd/lhfa/GPSTracker.java +++ b/app/src/main/java/com/lt/lrmd/lhfa/GPSTracker.java @@ -48,6 +48,11 @@ public GPSTracker(Context context) { } public Location getLocation() { + if ( Build.VERSION.SDK_INT >= 23 && + ContextCompat.checkSelfPermission( context, android.Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED && + ContextCompat.checkSelfPermission( context, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + return ; + } try { locationManager = (LocationManager) mContext .getSystemService(LOCATION_SERVICE); @@ -187,4 +192,4 @@ public void onClick(DialogInterface dialog, int which) { // Showing Alert Message alertDialog.show(); } -} \ No newline at end of file +}