Search code examples
androidgoogle-playnativescriptandroid-bluetoothgoogle-play-console

Android Nativescript App Prompting ACCESS_BACKGROUND_LOCATION


I'm trying to release an NS8 app on the Google Play Store. The app needs bluetooth to work, since it connects to other devices. I'm going to target SDK 30 due to Google Play policy.

I know that in order to get that to work, I need to declare the following permissions in the AndroidManifest

ACCESS_FINE_LOCATION and ACCESS_BACKGROUND_LOCATION

However, when I upload a Bundle to the Google Play, I get the following warning

This release includes permissions that haven't been declared in Play Console. Go to Sensitive app permissions to update your permission declarations.

I guess I need to make a prompt in the app to ask for background location permission. Using nativescript-community/ble I know request FINE_LOCATION already. But I'm wondering, how do I get an explicit prompt for background location access? I need one for my video.

EDIT: So I managed to find some code that manually prompts for location, so I'm trying to adapt it for ACCESS_BACKGROUND_LOCATION, but I still need help.

import {
   AndroidActivityRequestPermissionsEventData,
   AndroidActivityResultEventData,
   AndroidApplication,
   android as andApp
} from '@nativescript/core/application';

...

let permissionCb = (args: AndroidActivityRequestPermissionsEventData) => {
                        console.log(args);
                        console.log(args.requestCode);
                        console.log(args.permissions);
}
              

andApp.on(AndroidApplication.activityRequestPermissionsEvent, permissionCb);

const neededPermission = android.Manifest.permission.ACCESS_BACKGROUND_LOCATION;
                    

androidx.core.app.ActivityCompat.requestPermissions(this._getActivity(), [neededPermission], 0);

The problem is, my app isn't recognizing android.Manifest.permission.ACCESS_BACKGROUND_LOCATION. What should I do?


Solution

  • Turns out, that only the ACCESS_FINE_LOCATION was necessary since my app's bluetooth capability only scans in the foreground anyway.