"googleapiclient Is Not Connected Yet" Exception In Cast Application
Solution 1:
Google APIs for Android > GoogleApiClient
You should instantiate a client object in your Activity's onCreate(Bundle) method and then call connect() in onStart() and disconnect() in onStop(), regardless of the state.
The implementation of the GoogleApiClient
appears designed for only a single instance. It's best to instantiate it only once in onCreate
, then perform connections and disconnections using the single instance.
I would guess that only one GoogleApiClient
can be actually be connected, but multiple instances are receiving the onConnected
callback.
In your case it's probably fine to not call connect
in onStart
, but only in onRouteAdded
.
I think this issue is very similar to Fatal Exception: java.lang.IllegalStateException GoogleApiClient is not connected yet
Solution 2:
Have you declare following <meta>
tag
<application...>
...
<meta-dataandroid:name="com.google.android.gms.version"android:value="@integer/google_play_services_version" />
...
</application>
I just forgot to write so may you also stuck with this reason.
Thank you.
Solution 3:
From showcase app (Googlecast Github Sample CastHelloText-android ) receiver app is launched onRouteSelected (not onRouteAdded as you are doing in your code). I would try to change that. In case it does not work, I would add log lines in every method related to connection & session, and see what is happening.
Another tip: I have had crash with stopping the application (in case chromecast device is physically plugged out from power). Solution is to putCast.CastApi.stopApplication(apiClient);
inside if (apiClient.isConnected())
.
Solution 4:
It seems like you are calling GoogleApiClient before it is connected
move this line in onCreate()
// First we need to check availability of play servicesif (checkPlayServices()) {
// Building the GoogleApi client//buildGoogleApiClient();try {
mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(LocationServices.API).build();
mGoogleApiClient.connect();
}catch (IllegalStateException e)
{
Log.e("IllegalStateException", e.toString());
}
createLocationRequest();
}
Hope it helps you.
Post a Comment for ""googleapiclient Is Not Connected Yet" Exception In Cast Application"