java - .IllegalStateException: GoogleApiClient is not connected yet -


i read couple of solutions regarding problem none of them solved error. caused by: java.lang.illegalstateexception: googleapiclient not connected yet. code should move not error?

i error on genymotion emulator not on real life android phone. main problem cannot handle other things in welcome activity if don't fix this.

could me out this?

thanks.

import android.content.context; import android.content.intent; import android.content.pm.packagemanager; import android.location.address; import android.location.geocoder; import android.location.location; import android.location.locationmanager; import android.os.environment; import android.os.handler; import android.preference.preferencemanager; import android.support.annotation.nonnull; import android.support.annotation.nullable; import android.support.v4.app.activitycompat; import android.support.v4.content.contextcompat; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.windowmanager; import android.widget.toast;  import com.google.android.gms.common.connectionresult; import com.google.android.gms.common.api.googleapiclient; import com.google.android.gms.location.locationlistener; import com.google.android.gms.location.locationrequest; import com.google.android.gms.location.locationservices; import com.google.android.gms.maps.model.latlng;   import java.io.bufferedreader; import java.io.file; import java.io.filenotfoundexception; import java.io.fileoutputstream; import java.io.filereader; import java.io.ioexception; import java.io.inputstream; import java.util.arraylist; import java.util.list; import java.util.locale;  public class welcomeactivity extends appcompatactivity implements googleapiclient     .connectioncallbacks, googleapiclient.onconnectionfailedlistener, locationlistener { private static final int permission_request_access_fine_location = 100;  private locationrequest mlocationrequest; private googleapiclient mgoogleapiclient;   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     getsupportactionbar().hide();     getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager             .layoutparams.flag_fullscreen);     setcontentview(r.layout.activity_welcome);       locationmanager manager = (locationmanager) getsystemservice(context.location_service);     boolean statusofgps = manager.isproviderenabled(locationmanager.gps_provider);      if (!statusofgps) {         toast.maketext(this, "turn on gps gps cameras!", toast.length_short)                 .show();      }      mgoogleapiclient = new googleapiclient.builder(this)             .addapi(locationservices.api)             .addconnectioncallbacks(this)             .addonconnectionfailedlistener(this)             .build();     createlocationrequest();      if (!checkpermissions()) requestpermissions();  }   @override public void onstart() {     super.onstart();     mgoogleapiclient.connect(); }  @override public void onstop() {     super.onstop();     mgoogleapiclient.disconnect(); }  @override protected void onpause() {     super.onpause();     if (checkpermissions()) stoplocationupdates(); }  @override public void onresume() {     super.onresume();     if (checkpermissions() && mgoogleapiclient.isconnected()) startlocationupdates(); }  private void startlocationupdates() {     //noinspection missingpermission     locationservices.fusedlocationapi.requestlocationupdates(mgoogleapiclient,             mlocationrequest, this); }  private void stoplocationupdates() {     locationservices.fusedlocationapi.removelocationupdates(mgoogleapiclient, this); }  private boolean checkpermissions() {     return contextcompat.checkselfpermission(this, android.manifest.permission             .access_fine_location) == packagemanager.permission_granted; }  private void requestpermissions() {     if (activitycompat.shouldshowrequestpermissionrationale(this, android.manifest.permission             .access_fine_location)) {     } else {         activitycompat.requestpermissions(this,                 new string[]{android.manifest.permission.access_fine_location},                 permission_request_access_fine_location);     } }  private void createlocationrequest() {     mlocationrequest = new locationrequest();     mlocationrequest.setpriority(locationrequest.priority_high_accuracy); }  @override public void onconnected(@nullable bundle bundle) {     if (checkpermissions() && mgoogleapiclient.isconnected())         mlocationrequest = new locationrequest(); }  @override public void onconnectionsuspended(int i) {  }  @override public void onconnectionfailed(@nonnull connectionresult connectionresult) {  }  @override public void onlocationchanged(location location) {      }  @override public void onrequestpermissionsresult(int requestcode, @nonnull string[] permissions,                                        @nonnull int[] grantresults) {     switch (requestcode) {         case permission_request_access_fine_location: {             if (grantresults.length > 0 && grantresults[0] == packagemanager                     .permission_granted) {                 startlocationupdates();             } else {              }         }     } }  } 


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -