2

i'm trying to use Android Geofences in my App and test the App via Travis-CI. Everything works fine on my local device and on my local Emulator. But not on Travis-CI.

It turns out, that the Geofences couldn't be added because the network location provider is disabled. (I receive GEOFENCE_NOT_AVAILABLE error status)

Checking on my Location Settings with Settings.Secure.getInt(this.getContentResolver(), Settings.Secure.LOCATION_MODE) gives me LOCATION_MODE_SENSORS_ONLYback which means Network Location Provider is disabled, but GPS and other sensors are enabled, according to the Documentation.

As far as I know enabling network Location Provider programmatically is not possible due to Security concerns. See here

If I disable mobile network location in the settings Menu on my local device and on the local emulator i can reproduce the behaviour from the Emulator on Travis-CI.

Is there a way to configure the Emulator on Travis that the mobile network location in the settings menu is enabled from beginning? Or can i add a geofence in my app somehow even if the network provider is disabled?

Here is my travis.yml

language: android
cache: false
sudo: false
env:
  global:
  - ADB_INSTALL_TIMEOUT=16
android:
  components:
  - build-tools-22.0.1
  - android-21
  - extra-google-google_play_services
  - extra-google-m2repository
  - extra-android-m2repository
  - addon-google_apis-google-21
  - sys-img-armeabi-v7a-addon-google_apis-google-21

before_install:
- chmod +x gradlew
- android list target
- echo no | android create avd --force -n test -t "Google Inc.:Google APIs:21"
  --abi google_apis/armeabi-v7a
- emulator -avd test -no-skin -no-audio -no-window &
- chmod +x wait_for_emulator.sh
- ./wait_for_emulator.sh
- sleep 30

before_script:

- adb logcat &
- adb shell input keyevent 82 &
- sleep 30
- adb shell settings put secure location_providers_allowed off &
- sleep 30
- adb shell settings put secure location_providers_allowed network,gps,wifi &
- sleep 30
- adb shell input keyevent 22 &
- sleep 10
- adb shell input keyevent 23
- sleep 10



script:


- "./gradlew build connectedCheck --stacktrace --continue -PdisablePreDex"

Thanks for your help.

Update:

After some research and thanks to this post i found out that i can change the settings via this adb shell command:

settings put secure location_providers_allowed network,gps,wifi

But still there is user consent required. I tried to accept with:

input keyevent 22
input keyevent 23

This works on my local device and my local emulator, but still fails on the Travis-Emulator. I changed the attached travis.yml accordingly and the Travis-Logfile can be found here. After all the network provider is still not enabled and it seems the ConfirmAlertActivity pops up after the Application is started for testing and not when I give the enable command via adb.

Community
  • 1
  • 1
J-Bossi
  • 542
  • 6
  • 12

0 Answers0