android - Reset location provider to use actual GPS after mocking location -


as coding newbie, first question apologies if it's little rough around edges , code less epic.

i'm mocking locations in android , able mock gps_provider. when mocking app not running, location not return user's actual position. there way stop mocking locations real gps position returns , updates normal?

the code using mock locations (extract activity):

try     {         lm = (locationmanager) getsystemservice(context.location_service);         lm.requestlocationupdates(locationmanager.gps_provider, 50, 0, lis);          lm.addtestprovider(locationmanager.gps_provider, false, false, false, false, true, true, true, criteria.power_low, criteria.accuracy_fine);          loc = new location(locationmanager.gps_provider);         loc.setlatitude(51.5219145);         loc.setlongitude(-0.1285495);         loc.settime(system.currenttimemillis());         loc.setaccuracy(10);         loc.setelapsedrealtimenanos(systemclock.elapsedrealtimenanos());           t = new timer();          t.scheduleatfixedrate(new timertask() {             @override             public void run() {                 loc.settime(system.currenttimemillis());                 loc.setelapsedrealtimenanos(systemclock.elapsedrealtimenanos());                 lm.settestproviderlocation(locationmanager.gps_provider, loc);             }         }, 0, 2000);      }catch(securityexception e){         e.printstacktrace();     } 

i have tried removing mocked location provider with:

lm.settestproviderenabled(locationmanager.gps_provider, false); lm.cleartestproviderlocation(locationmanager.gps_provider);  if (lm.getprovider(locationmanager.gps_provider) != null){     log.i("remove", "test provider");     lm.removetestprovider(locationmanager.gps_provider); } 

the above run doesn't seem anything. suspect have replaced default location provider. there way restore it? i'd appreciate advice offer. thanks.

 lm.removetestprovider(locationmanager.gps_provider); 

when remove provider, let gps receive fresh location, fixed. can test it

  1. set mock location gps
  2. go googlemaps , see mock location (gps must enabled)
  3. turn app , stop mocking
  4. go again googlemaps, , wait until gps provider receive real location. take bit time, when tested in home, taken 1-2 minutes in balcony 5 seconds.

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -