androidlocationwifihotspot

Enable Location without user interaction (with privileged permissions)


I am developing an app which is installed in priv-app, so I can get all the system-permissions. I need to create an localOnlyHotspot without user-interaction. After rebooting the device, the "location mode" is off. I have to manually enable it or redirect the user to settings to do this (but the user has no input devices). Just to make clear: The device does not have GPS, only wifi for location determining. I also do not need to determine the devices location but the localOnlyHotspot needs enabled "locationMode" to work.

Thanks


Solution

  • The way I see it you have few options.

    1. If you have AdminManager object in your app, you can use setSecureSetting with Settings.Secure.LOCATION_MODE. Though it's deprecated it worked for me in Android 10 and if I remember correctly even in 11.

    Edit: Forgot to mention, this requires your app to be device owner.

    1. If 1 is not possible to apply, you can try running the command manually, being "settings put secure location_mode 1"