Possible race condition or programmer error in Google Fitness startSession - android

I am attempting to record Google Fit Sessions for periods in sports activity in my Referee Watch. I start a session at the beginning of a period and then stop it at the end of the period.
I sometimes get an interesting exception when I start a Fitness session using this code:
private Session startFitSession(final Game currentGame) {
final Session fitSession;
try {
String sessionBaseName = currentGame.getGameTitle();
if (sessionBaseName.isEmpty()) sessionBaseName = currentGame.getGameLocation();
if (sessionBaseName.isEmpty()) sessionBaseName = RefWatchUtil.timeMsToString(currentGame.getActualStartMs(),RefWatchUtil.dateTimeFormatStart);
final String sessionName = sessionBaseName + ": "
+ String.format(getResources().getString(R.string.fitness_period_label),mCurrentPeriod);
//use this to try to avoid error message about creating a session in the future
final long startTime = System.currentTimeMillis()-TimeUnit.SECONDS.toMillis(10);
fitSession = new Session.Builder()
.setName(sessionName)
.setIdentifier(sessionName)
.setDescription(mCurrentGame.getGameDescription())
.setStartTime(startTime, TimeUnit.MILLISECONDS)
.setActivity(FitnessActivities.RUNNING_JOGGING)
.build();
Fitness.SessionsApi.startSession(mGoogleApiClient, fitSession)
.setResultCallback(new ResultCallback<Status>() {
#Override
public void onResult(#NonNull Status status) {
if (status.isSuccess()) {
Log.i(TAG, "Successfully started Session " + sessionName);
} else {
Log.i(TAG, "There was a problem starting the session " + sessionName
+ ": " + status.getStatusMessage());
}
}
});
} catch (RuntimeException e){
Log.i(TAG, "There was a runtime exception starting the session: " + e.getLocalizedMessage());
return null;
}
return fitSession;
}
The exception is:
There was a runtime exception starting the session: Cannot start a session in the future
So it occurred to me that perhaps Session.Builder() looks at the "present" as when the new Builder() call, so I changed to the following code:
...
final long startTime = System.currentTimeMillis();
fitSession = new Session.Builder()
.setName(sessionName)
.setIdentifier(sessionName)
.setDescription(mCurrentGame.getGameDescription())
.setStartTime(startTime, TimeUnit.MILLISECONDS)
...
Same error.
So now I subtract an arbitrary 10 seconds from the startTime and that seems to have fixed the problem.
But (a) is there a better way of making this call (afaict, you can't call setStartTime with a 0 argument to get "current time") and (b) is this a common pattern for Builder type calls?

Related

uber requestRide() method Response Error 401: Unauthorized

I am getting Error when I try to call requestRide() method on Uber api. The response body is null and the response message is "Unauthorized" with error code 401; whereas the onResponse() callback method is executing but onFailure() callback method is not executing.
Here is my code for calling requestRide() and implementing the callback interface...
private void requestForNewRide(RidesService service, int position){
RideRequestParameters rideRequestParameters = new RideRequestParameters.Builder().setPickupCoordinates(PICKUP_LATITUDE, PICKUP_LONGITUDE)
.setProductId(productIds.get(position))
.setFareId(fareIds.get(position))
.setDropoffCoordinates(DROPOFF_LATITUDE, DROPOFF_LONGITUDE)
.build();
service.requestRide(rideRequestParameters).enqueue(new Callback<Ride>() {
#Override
public void onResponse(Call<Ride> call, Response<Ride> response) {
if (response.isSuccessful()) {
Toast.makeText(CustomActivity.this, "Request ride success", Toast.LENGTH_SHORT).show();
try {
//ride details
String rideId = response.body().getRideId();
String rideStatus = response.body().getStatus();
Integer rideEta = response.body().getEta(); //estimated time of arrival in min
Float rideSurgeMultiplier = response.body().getSurgeMultiplier(); //rise in price
Driver rideDriver = response.body().getDriver();
Location rideLocation = response.body().getLocation();
Vehicle rideVehicle = response.body().getVehicle();
//ride driver details
String driverName = rideDriver.getName();
String driverPhoneNumber = rideDriver.getPhoneNumber();
String driverPictureUri = rideDriver.getPictureUrl();
Float driverRating = rideDriver.getRating();
//ride Location details
Float rideLocationLatitude = rideLocation.getLatitude();
Float rideLocationLongitude = rideLocation.getLongitude();
Integer rideLocationBearing = rideLocation.getBearing();
//ride Vehicle details
String rideVehicleLicencePlate = rideVehicle.getLicensePlate();
String rideVehicleMake = rideVehicle.getMake();
String rideVehicleModel = rideVehicle.getModel();
String rideVehiclePictureUrl = rideVehicle.getPictureUrl();
//Log
Log.d("uberridedetails", "rideId: " + rideId);
Log.d("uberridedetails", "rideStatus: " + rideStatus);
Log.d("uberridedetails", "rideEta: " + rideEta);
Log.d("uberridedetails", "rideSurgeMultiplier: " + rideSurgeMultiplier);
Log.d("uberridedetails", "driverName: " + driverName);
Log.d("uberridedetails", "driverPhoneNumber: " + driverPhoneNumber);
Log.d("uberridedetails", "driverPictureUri: " + driverPictureUri);
Log.d("uberridedetails", "driverRating: " + driverRating);
Log.d("uberridedetails", "rideLocationLatitude: " + rideLocationLatitude);
Log.d("uberridedetails", "rideLocationLongitude: " + rideLocationLongitude);
Log.d("uberridedetails", "rideLocationBearing: " + rideLocationBearing);
Log.d("uberridedetails", "rideVehicleLicencePlate: " + rideVehicleLicencePlate);
Log.d("uberridedetails", "rideVehicleMake: " + rideVehicleMake);
Log.d("uberridedetails", "rideVehicleModel: " + rideVehicleModel);
Log.d("uberridedetails", "rideVehiclePictureUrl: " + rideVehiclePictureUrl);
} catch (Exception e) {
e.printStackTrace();
}
}else {
Toast.makeText(CustomActivity.this, "Error: "+response.message(), Toast.LENGTH_SHORT).show();
}
}
#Override
public void onFailure(Call<Ride> call, Throwable t) {
Toast.makeText(CustomActivity.this, "Failed to request ride", Toast.LENGTH_SHORT).show();
}
});
}
I have already checked the param productId and FareId is valid, which I am getting from the api itself (by calling estimateRide() I get Price object from that I have got the fareId. And by calling getProducts() on RideService object I have got the productId.
This is the code for set up...
SessionConfiguration config = new SessionConfiguration.Builder()
.setClientId(getResources().getString(R.string.client_id))
.setRedirectUri(getResources().getString(R.string.redirect_url))
.setEnvironment(SessionConfiguration.Environment.SANDBOX)
.setScopes(Arrays.asList(Scope.PROFILE, Scope.RIDE_WIDGETS, Scope.REQUEST, Scope.REQUEST_RECEIPT))
.build();
UberSdk.initialize(config);
And ...
LoginCallback loginCallback = new LoginCallback() {
#Override
public void onLoginCancel() {
// User canceled login
Toast.makeText(CustomActivity.this, "User canceled login", Toast.LENGTH_SHORT).show();
}
#Override
public void onLoginError(#NonNull AuthenticationError error) {
// Error occurred during login
Toast.makeText(CustomActivity.this, "Error occurred during login", Toast.LENGTH_SHORT).show();
}
#Override
public void onLoginSuccess(#NonNull AccessToken accessToken) {
// Successful login! The AccessToken will have already been saved.
Toast.makeText(CustomActivity.this, "Successful login! The AccessToken will have already been saved.", Toast.LENGTH_SHORT).show();
createSession();
}
#Override
public void onAuthorizationCodeReceived(#NonNull String authorizationCode) {
Toast.makeText(CustomActivity.this, "Authorization code received", Toast.LENGTH_SHORT).show();
createSession();
}
};
AccessTokenManager accessTokenManager = new AccessTokenManager(getApplicationContext());
LoginManager loginManager = new LoginManager(accessTokenManager, loginCallback);
loginManager.setRedirectForAuthorizationCode(true);
loginManager.login(this);
mAccessTokenManager = accessTokenManager;
mLoginManager = loginManager;
Note1: These are the scopes I am using...
Scope.PROFILE, Scope.RIDE_WIDGETS, Scope.REQUEST, Scope.REQUEST_RECEIPT
Note2: I am logging in with my developer account.
Let me know if I should mention any other details.
Absolutely I have found out the solution on my own.
I noticed that the onLoginSuccess() callback method is being called only when I am using GENERAL SCOPEs.
Whenever I am using a RESTRICTED SCOPE, the method is not being called, instead another callback method named onAuthorizationCodeReceived() is being called.
Then I have found out, whenever the onAuthorizationCodeReceived() method is called, there is no access token saved in the AccessTokenManager object. Thus without the access token, when I try to request a ride Error returns "Unauthorized".
So, I tried to figure out how to generate Access token using the authorization code. I found no doc regarding this process in the Android section. Then I have found out the solution in the REST web service api.
Here is the LINK of my answer...
NOTE: There is no mention of the callback method onAuthorizationCodeReceived() in the Uber Doc.

Google Fit Session title not "sticking"

My Referee watch creates a Google Fit Session using the following code:
private void insertFitSession(final Game currentGame, final Period period,
final long periodStartTime, final long periodEndTime) {
//add the detailed Sensor data (using History API) if available
boolean activityWasInserted = false;
if (!RefWatchUtil.isRefWatchFree()) {
//If there are speeds then we will insert an activity
//4.5.09: Unfortunately mFitnessDataSets[] can have leftover data from a period where you did track fitness
//So we had to replace with period-by-period dataSets
activityWasInserted = (period.getFitnessDataSet(SPEED_LISTENER_IDX) != null)
&& !period.getFitnessDataSet(SPEED_LISTENER_IDX).isEmpty();
}
//create a Session in Google Fit for the period that just completed
//(this happens even for Free)
try {
String sessionBaseName = currentGame.getTitle();
if (sessionBaseName.isEmpty()) sessionBaseName = currentGame.getLocation();
if (sessionBaseName.isEmpty()) sessionBaseName = RefWatchUtil.timeMillisToDefaultShortDateTime(currentGame.getStartTimeMillis());
final String sessionName = sessionBaseName + ": " + String.format(getResources().getString(R.string.fitness_period_label), period.getPeriodNum());
final Session.Builder fitnessSessionBuilder = new Session.Builder();
fitnessSessionBuilder
.setName(sessionName)
.setIdentifier(sessionName)
.setDescription(mCurrentGame.getDescription())
.setStartTime(periodStartTime, TimeUnit.MILLISECONDS)
.setEndTime(periodEndTime, TimeUnit.MILLISECONDS);
//If we're Free, then we don't have real fitness session data and just guess at Jogging
// (also if we have no Activity data in Pro)
if (RefWatchUtil.isRefWatchFree() || !activityWasInserted) {
fitnessSessionBuilder.setActivity(FitnessActivities.RUNNING_JOGGING);
}
final Session fitSession = fitnessSessionBuilder.build();
SessionInsertRequest insertRequest = new SessionInsertRequest.Builder()
.setSession(fitSession)
.build();
Fitness.SessionsApi.insertSession(mFitnessApiClient, insertRequest)
.setResultCallback(new ResultCallback<Status>() {
#Override
public void onResult(#NonNull Status status) {
if (status.isSuccess()) {
Log.d(TAG, "Successfully inserted Session " + sessionName);
} else {
Log.d(TAG, "There was a problem inserting the session " + sessionName
+ ": " + status.getStatusCode() + " " + status.getStatusMessage());
}
}
});
} catch (RuntimeException e){
Log.e(TAG, "There was a runtime exception inserting the session: " + e.getLocalizedMessage());
}
}
Note the sessionName defaults to either Title, Location, or Time appended with the current Period. This has been working great.
Recently (last month or so?) the Fit session is correctly inserted (I can track it in the log) but the Name doesn't stick. Instead I get "25 min running" for some, but not all, of them.
Has anybody else experienced this type of override by Fit?

Google Fit: save medical data

Note
I couldn't find any similar question on StackOverflow. In the only threads I found, they asked about reading, not writing.
Issue
I am integrating GoogleFit but I am not able to insert blood pressure data to the HistoryApi. I successfully login, but when adding data, I always get:
Status{statusCode=TIMEOUT, resolution=null}
I tried putting the code in a AsyncTask and inserting synchronously with .await(1, TimeUnit.MINUTES) but still getting the same error.
I also tried uninstalling GoogleFit and I have internet access via WiFi.
If it helps,S Health is working fine.
Code
public static void saveBloodPressure(Context context, long timestampMillis, int systolic, int diastolic){
// Create DataSource
DataSource bloodPressureSource = new DataSource.Builder()
.setDataType(HealthDataTypes.TYPE_BLOOD_PRESSURE)
.setAppPackageName(context)
.setStreamName(TAG + " - blood pressure")
.setType(DataSource.TYPE_RAW)
.build();
// Create DataPoint with DataSource
DataPoint bloodPressure = DataPoint.create(bloodPressureSource);
bloodPressure.setTimestamp(timestampMillis, TimeUnit.MILLISECONDS);
bloodPressure.getValue(HealthFields.FIELD_BLOOD_PRESSURE_SYSTOLIC).setFloat(systolic);
bloodPressure.getValue(HealthFields.FIELD_BLOOD_PRESSURE_DIASTOLIC).setFloat(diastolic);
// Create DataSet
DataSet dataSet = DataSet.create(bloodPressureSource);
dataSet.add(bloodPressure);
// Create Callback to manage Result
ResultCallback<com.google.android.gms.common.api.Status> callback = new ResultCallback<com.google.android.gms.common.api.Status>() {
#Override
public void onResult(#NonNull com.google.android.gms.common.api.Status status) {
if (status.isSuccess()) {
Log.v("GoogleFit", "Success: " + status);
}else{
Log.v("GoogleFit", "Error: " + status);
}
}
};
// Execute insert
Fitness.HistoryApi.insertData(mGoogleApiClient, dataSet)
.setResultCallback(callback, 1, TimeUnit.MINUTES);
}
In case someone asks, I will also put the GoogleApiClient initialization below.
GoogleApiClient initialization
public static void initialize(final FragmentActivity activity){
// Setup Callback listener
GoogleApiClient.ConnectionCallbacks connectionCallbacks = new GoogleApiClient.ConnectionCallbacks() {
#Override
public void onConnected(Bundle bundle) {
Log.i(TAG, "Connected! ");
// Now you can make calls to the Fitness APIs.
//subscribe();
}
#Override
public void onConnectionSuspended(int i) {
// If your connection to the sensor gets lost at some point,
// you'll be able to determine the reason and react to it here.
if (i == GoogleApiClient.ConnectionCallbacks.CAUSE_NETWORK_LOST) {
Log.i(TAG, "1 Connection lost. Cause: Network Lost.");
} else if (i == GoogleApiClient.ConnectionCallbacks.CAUSE_SERVICE_DISCONNECTED) {
Log.i(TAG, "2 Connection lost. Reason: Service Disconnected");
}
}
};
// Handle Failed connection
GoogleApiClient.OnConnectionFailedListener connectionFailed = new GoogleApiClient.OnConnectionFailedListener() {
#Override
public void onConnectionFailed(#NonNull ConnectionResult result) {
Log.i(TAG, "3 Google Play services connection failed. Cause: " + result.toString());
Toast.makeText(activity, "4 Exception while connecting to Google Play services: " +
result.getErrorMessage() + ":" + result.getErrorCode(), Toast.LENGTH_SHORT).show();
}
};
// Create Google Api Client
mGoogleApiClient = new GoogleApiClient.Builder(activity)
.addConnectionCallbacks(connectionCallbacks)
.enableAutoManage(activity, connectionFailed)
.addScope(new Scope(Scopes.FITNESS_BODY_READ_WRITE))
.addApi(Fitness.HISTORY_API)
.build();
}
Thanks!
Even though it seems a connection timeout error, it seems to me that you are missing something.
I'm not sure if this will help but FITNESS_BODY_READ_WRITE scope needs permissions.
Are you authorizing with Fitness API before calling Fitness.HistoryApi.insertData?
For which user are you inserting data?
See here: https://developers.google.com/android/guides/permissions
And here (Authorization): https://developers.google.com/android/reference/com/google/android/gms/fitness/Fitness
Follow the guide on Insert data
Insert data
To insert data into the fitness history, first create a DataSet
instance:
// Set a start and end time for our data, using a start time of 1 hour before this moment.
Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
cal.add(Calendar.HOUR_OF_DAY, -1);
long startTime = cal.getTimeInMillis();
// Create a data source
DataSource dataSource = new DataSource.Builder()
.setAppPackageName(this)
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setStreamName(TAG + " - step count")
.setType(DataSource.TYPE_RAW)
.build();
// Create a data set
int stepCountDelta = 950;
DataSet dataSet = DataSet.create(dataSource);
// For each data point, specify a start time, end time, and the data value -- in this case,
// the number of new steps.
DataPoint dataPoint = dataSet.createDataPoint()
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS);
dataPoint.getValue(Field.FIELD_STEPS).setInt(stepCountDelta);
dataSet.add(dataPoint);
After you create a DataSet instance, use the HistoryApi.insertData
method and wait synchronously or provide a callback method to check
the status of the insertion.
// Then, invoke the History API to insert the data and await the result, which is // possible here because of the {#link AsyncTask}. Always include a timeout when calling // await() to prevent hanging that can occur from the service being shutdown because // of low memory or other conditions. Log.i(TAG, "Inserting the dataset in the History API."); com.google.android.gms.common.api.Status insertStatus
=
Fitness.HistoryApi.insertData(mClient, dataSet)
.await(1, TimeUnit.MINUTES);
// Before querying the data, check to see if the insertion succeeded. if (!insertStatus.isSuccess()) {
Log.i(TAG, "There was a problem inserting the dataset.");
return null; }
// At this point, the data has been inserted and can be read. Log.i(TAG, "Data insert was successful!");

TWILIO call issue due to 2 missing digit

I am working on an Android application that uses Twilio to make phone calls and to send SMS.
While making a call I get the IVRS message "Your call cannot be completed because of two missing digits".
The FROM number is "+18669135337" and TO number is "(949) 439-7570" or "+19494397570"
What could be the reason thats causing this issue?
This is the code snippet thats making the call
public void connect(String toNumber, ConnectionListener listener) {
Map<String, String> parameters = new HashMap<String, String>();
Log.e(TAG, "Calling from " + mFromNumber);
Log.e(TAG, "Calling to " + toNumber);
Log.e(TAG, "mDevice State is " + mDevice.getState());
parameters.put(Constants.KEY_TO_NUMBER, toNumber);
parameters.put(Constants.KEY_FROM_NUMBER, mFromNumber);
mConnection = mDevice.connect(parameters, listener);
Log.e(TAG, "Connection status " + mConnection);
if (mConnection == null) {
Log.w(TAG, "Failed to create new connection");
}
}

Connecting to existing Google Chromecast Session from Android (for generic remote control)

I am creating a generic Chromecast remote control app. Most of the guts of the app are already created and I've managed to get Chromecast volume control working (by connecting to a Chromecast device along side another app that is casting - YouTube for example).
What I've having difficult with is performing other media commands such as play, pause, seek, etc.
Use case example:
1. User opens YouTube on their android device and starts casting a video.
2. User opens my app and connects to the same Chromecast device.
3. Volume control from my app (works now)
4. Media control (play, pause, etc) (does not yet work)
I found the Cast api reference that explains that you can sendMessage(ApiClient, namespace, message) with media commands; however the "message" (JSON) requires the sessionId of the current application (Youtube in this case). I have tried the following, but the connection to the current application always fails; status.isSuccess() is always false:
Cast.CastApi
.joinApplication(mApiClient)
.setResultCallback(
new ResultCallback<Cast.ApplicationConnectionResult>() {
#Override
public void onResult(
Cast.ApplicationConnectionResult result) {
Status status = result.getStatus();
if (status.isSuccess()) {
ApplicationMetadata applicationMetadata = result
.getApplicationMetadata();
sessionId = result.getSessionId();
String applicationStatus = result
.getApplicationStatus();
boolean wasLaunched = result
.getWasLaunched();
Log.i(TAG,
"Joined Application with sessionId: "
+ sessionId
+ " Application Status: "
+ applicationStatus);
} else {
// teardown();
Log.e(TAG,
"Could not join application: "
+ status.toString());
}
}
});
Is is possible to get the sessionId of an already running cast application from a generic remote control app (like the one I am creating)? If so, am I right in my assumption that I can then perform media commands on the connected Chromecast device using something like this:
JSONObject message = new JSONObject();
message.put("mediaSessionId", sessionId);
message.put("requestId", 9999);
message.put("type", "PAUSE");
Cast.CastApi.sendMessage(mApiClient,
"urn:x-cast:com.google.cast.media", message.toString());
Update:
I have tried the recommendations provided by #Ali Naddaf but unfortunately they are not working. After creating mRemoteMediaPlayer in onCreate, I also do requestStatus(mApiClient) in the onConnected callback (in the ConnectionCallbacks). When I try to .play(mApiClient) I get an IllegalStateException stating that there is no current media session. Also, I tried doing joinApplication and in the callback performed result.getSessionId; which returns null.
A few comments and answers:
You can get the sessionId from the callback of launchApplication or joinApplication; in the "onResult(result)", you can get the sessionId from: result.getSessionId()
YouTube is still not on the official SDK so YMMV, for apps using official SDK, you should be able to use the above approach (most of it)
Why are you trying to set up a message yourself? Why not building a RemoteMediaPlayer and using play/pause that is provided there? Whenever you are working with the media playback through the official channel, always use the RemoteMediaPlayer (don't forget to call requestStatus() on it after creating it).
Yes it is possible , First you have to save sesionId and CastDevice device id
and when remove app from background and again open app please check is there sessionId then call bello line.
Cast.CastApi.joinApplication(apiClient, APP_ID,sid).setResultCallback(connectionResultCallback);
if you get success result then need to implement further process in connectionResultCallback listener.
//Get selected device which you selected before
#Override
public void onRouteAdded(MediaRouter router, MediaRouter.RouteInfo route) {
// Log.d("Route Added", "onRouteAdded");
/* if (router.getRoutes().size() > 1)
Toast.makeText(homeScreenActivity, "'onRouteAdded :: " + router.getRoutes().size() + " -- " + router.getRoutes().get(1).isSelected(), Toast.LENGTH_SHORT).show();
else
Toast.makeText(homeScreenActivity, "'onRouteAdded :: " + router.getRoutes(), Toast.LENGTH_SHORT).show();*/
if (router != null && router.getRoutes() != null && router.getRoutes().size() > 1) {
// Show the button when a device is discovered.
// Toast.makeText(homeScreenActivity, "'onRouteAdded :: " + router.getRoutes().size() + " -- " + router.getRoutes().get(1).isSelected(), Toast.LENGTH_SHORT).show();
mMediaRouteButton.setVisibility(View.VISIBLE);
titleLayout.setVisibility(View.GONE);
castName.setVisibility(View.VISIBLE);
selectedDevice = CastDevice.getFromBundle(route.getExtras());
routeInfoArrayList = router.getRoutes();
titleLayout.setVisibility(View.GONE);
if (!isCastConnected) {
String deid = MyPref.getInstance(homeScreenActivity).readPrefs(MyPref.CAST_DEVICE_ID);
for (int i = 0; i < routeInfoArrayList.size(); i++) {
if (routeInfoArrayList.get(i).getExtras() != null && CastDevice.getFromBundle(routeInfoArrayList.get(i).getExtras()).getDeviceId().equalsIgnoreCase(deid)) {
selectedDevice = CastDevice.getFromBundle(routeInfoArrayList.get(i).getExtras());
routeInfoArrayList.get(i).select();
ReSelectedDevice(selectedDevice, routeInfoArrayList.get(i).getName());
break;
}
}
}
}
}
//Reconnect google Api Client
public void reConnectGoogleApiClient() {
if (apiClient == null) {
Cast.CastOptions apiOptions = new
Cast.CastOptions.Builder(selectedDevice, castClientListener).build();
apiClient = new GoogleApiClient.Builder(this)
.addApi(Cast.API, apiOptions)
.addConnectionCallbacks(reconnectionCallback)
.addOnConnectionFailedListener(connectionFailedListener)
.build();
apiClient.connect();
}
}
// join Application
private final GoogleApiClient.ConnectionCallbacks reconnectionCallback = new GoogleApiClient.ConnectionCallbacks() {
#Override
public void onConnected(Bundle bundle) {
// Toast.makeText(homeScreenActivity, "" + isDeviceSelected(), Toast.LENGTH_SHORT).show();
try {
String sid = MyPref.getInstance(homeScreenActivity).readPrefs(MyPref.CAST_SESSION_ID);
String deid = MyPref.getInstance(homeScreenActivity).readPrefs(MyPref.CAST_DEVICE_ID);
if (sid != null && deid != null && sid.length() > 0 && deid.length() > 0)
Cast.CastApi.joinApplication(apiClient, APP_ID, sid).setResultCallback(connectionResultCallback);
isApiConnected = true;
} catch (Exception e) {
}
}
#Override
public void onConnectionSuspended(int i) {
isCastConnected = false;
isApiConnected = false;
}
};

Categories

Resources