Permission Request in Android
Add the required permissions to the AndroidManifest.xml
file.
//Location permissions
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
//Bluetooth permissions
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
//Network permissions
<uses-permission android:name="android.permission.INTERNET" />
Besides being decalred as static, location permissions should also be requsted in the activity as follows:
registerForActivityResult(ActivityResultContracts.RequestPermission())
{ granted ->
//Result callback
if (granted) {
//Permission granted
} else {
//Permission denied
}
}.launch(android.Manifest.permission.ACCESS_FINE_LOCATION)
Add the code above to the activity's onCreate()
method, so that the app will request location permissions whenever being launched.