diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml
index d39b6f11..9eb4e1bc 100644
--- a/android/src/main/AndroidManifest.xml
+++ b/android/src/main/AndroidManifest.xml
@@ -7,6 +7,7 @@
+
diff --git a/android/src/main/java/org/fossasia/badgemagic/ui/DrawerActivity.kt b/android/src/main/java/org/fossasia/badgemagic/ui/DrawerActivity.kt
index 48690100..bb7a0afc 100644
--- a/android/src/main/java/org/fossasia/badgemagic/ui/DrawerActivity.kt
+++ b/android/src/main/java/org/fossasia/badgemagic/ui/DrawerActivity.kt
@@ -58,6 +58,8 @@ class DrawerActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedLi
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+ checkLocationPermission()
+
binding = ActivityDrawerBinding.inflate(layoutInflater)
setContentView(binding.root)
@@ -380,4 +382,35 @@ class DrawerActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedLi
drawerLayout.closeDrawer(GravityCompat.START)
return true
}
+
+ private fun hasLocationPermission(): Boolean {
+ return ContextCompat.checkSelfPermission(
+ this, Manifest.permission.ACCESS_FINE_LOCATION
+ ) == PackageManager.PERMISSION_GRANTED
+ }
+ private fun checkLocationPermission() {
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED ||
+ ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
+ ) {
+
+ // Show an explanation to the user why the permission is needed
+ if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION) ||
+ ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_COARSE_LOCATION)
+ ) {
+
+ AlertDialog.Builder(this)
+ .setTitle("Location Permission Needed")
+ .setMessage("This app needs the Location permission to scan for nearby ble devices. Please grant the permission.")
+ .setPositiveButton("OK") { _, _ ->
+ }
+ .create()
+ .show()
+ } else {
+ ActivityCompat.requestPermissions(
+ this, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
+ REQUEST_PERMISSION_CODE
+ )
+ }
+ }
+ }
}