Issue
I'm trying to turn on or off the location of the device depending on what I want to test.
I've already looked into Test-Butler but turns out that I can't use it because of this:
Test Butler helper app requires an emulator image with stock Android else it won't install, therefore it will not work with non-stock emulator images such as ones with Google APIs or Google Play! and
And I'm implementing Google Maps in my app and so on Google API and google play are on my device so this looks like it leads to an error crash and isn't a solution for my case.
Question: What should I look into for turning on or off before a test?
Solution
You will have to check if location is enabled and only enable it when it's not.
You can check if location is enabled like this:
public boolean isLocationEnabled(Context context) {
int locationMode = 0;
String locationProviders;
try {
locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
} catch (SettingNotFoundException e) {
e.printStackTrace();
return false;
}
return locationMode != Settings.Secure.LOCATION_MODE_OFF;
}
If the above returns false
then you can enable it. Then do your "test".
Answered By - HB.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.