android - OnLocationChanged Won't Work Anymore, on many devices -
disclaimer: know there other questions similar want try , create super simpler case others recreate problem
i've been using similar code below request location updates using google play services past few months , worked fine. reason onlocationchanged no longer called. happens across whole range of test devices. i'm using play services 7.0.0. request updates , nothing happens. suspect related recent code update made (albeit 1 had nothing location system) i'm clueless find fix. when revert commit, still have problem -- on old code worked fine!
i've set code totally new sample application , played options locationrequest object fun nothing... stops after log, "onconnected, requestlocationupdates" after onconnected called.
thanks help!
similar:
- android gps onlocationchanged never called
- android onlocationchanged never called
- onlocationchanged() never called
relevant manifest entries:
<application <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> ..... </application> <uses-permission android:name="android.permission.access_location" /> <uses-permission android:name="android.permission.access_coarse_location" /> <uses-permission android:name="android.permission.access_fine_location" />
sample activity:
public class myactivity extends activity { context act = this; private googleapiclient mgoogleapiclient; string tag = "locationservice.java"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_my); new mylocationcallbacks().buildgoogleapiclient(); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.my, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } private class mylocationcallbacks implements googleapiclient.connectioncallbacks, googleapiclient.onconnectionfailedlistener, com.google.android.gms.location.locationlistener { public void buildgoogleapiclient() { mgoogleapiclient = new googleapiclient.builder(act) .addconnectioncallbacks(this) .addonconnectionfailedlistener(this) .addapi(locationservices.api) .build(); //log.i(tag, "connected yet? " + mgoogleapiclient.isconnecting() + " " + mgoogleapiclient.isconnected()); mgoogleapiclient.connect(); //log.i(tag, "connected yet? " + mgoogleapiclient.isconnecting() + " " + mgoogleapiclient.isconnected()); } @override public void onconnected(bundle bundle) { log.i(tag, "connected googleapiclient"); locationrequest locationrequest = new locationrequest(); locationrequest.setexpirationduration(30000); locationrequest.setpriority(locationrequest.priority_high_accuracy); log.d(tag, "onconnected, requestlocationupdates"); locationservices.fusedlocationapi.requestlocationupdates(mgoogleapiclient, locationrequest, this); } @override public void onlocationchanged(location locationa) { log.d(tag, locationa.getlongitude() + " :: " + locationa.getlatitude()); } @override public void onconnectionsuspended(int i) { log.d(tag, "onconnectionsuspended called"); } @override public void onconnectionfailed(connectionresult connectionresult) { log.d(tag, "onconnectionfailed called"); } }
}
i how post question before finding answer...
the above code works fine, didn't set interval. on locationrequest, call setinterval(whatever needed)... goodnight.
Comments
Post a Comment