android - getTriggeringLocation always returns null -


i have problem coming along android fused location api. have intentlistener service need receive locations periodically. create , connect googleapiclient successfully, request receive location updates through pendingintent, every time call geofencingevent.gettriggeringlocation return value null.

here's code:

private void createlocationrequest() {     mlocationrequest = new locationrequest();     mlocationrequest.setinterval(interval);     mlocationrequest.setfastestinterval(fastest_interval);     mlocationrequest.setpriority(locationrequest.priority_high_accuracy); }  private void startlocationlistener(context context) {     if (!isgoogleplayservicesavailable(context)) {         log.d(tag, "no google play services.");         return;     }      createlocationrequest();     mgoogleapiclient = new googleapiclient.builder(context)             .addapi(locationservices.api)             .addconnectioncallbacks(this)             .addonconnectionfailedlistener(this)             .build();      mgoogleapiclient.connect();     }  private void startlocationupdates(context context) {     intent = new intent(context, intentlistener.class);     pendingintent pi = pendingintent.getservice(context, 0, i, pendingintent.flag_update_current);      com.google.android.gms.common.api.pendingresult<status> pendingresult = locationservices.fusedlocationapi.requestlocationupdates(             mgoogleapiclient, mlocationrequest, pi);     log.d(tag, "location update started ..............: "); }  @override protected void onhandleintent(intent intent) {     log.d(tag, "inteeent");     string action = intent.getaction();      if(actions.action_start_intent_listener.equals(action)) {         init(this);     }     else {         geofencingevent event = geofencingevent.fromintent(intent);         if(event == null) log.d(tag, "null event");         if(event.gettriggeringlocation() == null) log.d(tag, "null location"); // **<-- problem here**         if (event == null || event.gettriggeringlocation() == null) {             return;         }          location location = event.gettriggeringlocation();         log.d(tag, "locationc: " + location.getlatitude() + ", " + location.getlongitude());     } } 

and here's manifest

<application     android:allowbackup="true"     android:icon="@mipmap/ic_launcher"     android:label="@string/app_name"     android:theme="@style/apptheme" >     <activity         android:name="com.srn.app.mainactivity"         android:label="@string/app_name" >         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity>     <service android:enabled="true" android:name="com.srn.app.intentlistener"></service> </application>  <meta-data     android:name="com.google.android.gms.version"     android:value="@integer/google_play_services_version" /> 

i'm running app in x86 emulator android 5.1 installed.

any idea problem?

thanks.

the geofencing api must registered via geofencingapi.addgeofences(). assuming want receive location information requestlocationupdates() call doing, should use locationresult.extractresult() in place of geofencingevent.fromintent().

an alternative older versions of google play services use key key_location_changed extract single location intent:

location location = intent.getparcelableextra(     locationservices.fusedlocationproviderapi.key_location_changed); 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -