protected override void OnHandleIntent(Intent intent) { mGoogleApiClient.BlockingConnect(Constants.CONNECTION_TIME_OUT_MS, TimeUnit.Milliseconds); // Query calendar events in the next 24 hours Time time = new Time(); time.SetToNow(); long beginTime = time.ToMillis(true); time.MonthDay++; time.Normalize(true); long endTime = time.Normalize(true); List <Event> events = QueryEvents(this, beginTime, endTime); foreach (Event ev in events) { PutDataMapRequest putDataMapRequest = ev.ToPutDataMapRequest(); if (mGoogleApiClient.IsConnected) { WearableClass.DataApi.PutDataItem(mGoogleApiClient, putDataMapRequest.AsPutDataRequest()).Await(); } else { Log.Error(Constants.TAG, "Failed to send data item: " + putDataMapRequest + " - Client disconnected from Google Play Services"); } } mGoogleApiClient.Disconnect(); }
private async Task CreateLocationDataRequest(bool urgent) { // Don't send anything unless we're setup if (!Settings.WeatherLoaded) { return; } if (mWearNodesWithApp == null) { // Create requests if nodes exist with app support mWearNodesWithApp = await FindWearDevicesWithApp(); if (mWearNodesWithApp == null || mWearNodesWithApp.Count == 0) { return; } } PutDataMapRequest mapRequest = PutDataMapRequest.Create(WearableHelper.LocationPath); var homeData = Settings.HomeData; mapRequest.DataMap.PutString("locationData", homeData?.ToJson()); mapRequest.DataMap.PutLong("update_time", DateTime.UtcNow.Ticks); PutDataRequest request = mapRequest.AsPutDataRequest(); if (urgent) { request.SetUrgent(); } await WearableClass.DataApi.PutDataItem(mGoogleApiClient, request); Logger.WriteLine(LoggerLevel.Info, "{0}: CreateLocationDataRequest(): urgent: {1}", TAG, urgent.ToString()); }
private Task SendData(PutDataMapRequest mapReq) { return(Task.Run(() => { foreach (var node in clientNodes) { WearableClass.DataApi.PutDataItem(googleApiClient, mapReq.AsPutDataRequest()); } })); }
public PutDataRequest ToPutDataRequest() { PutDataMapRequest request = PutDataMapRequest.Create("/question/" + questionIndex); DataMap dataMap = request.DataMap; dataMap.PutString(Constants.QUESTION, question); dataMap.PutInt(Constants.QUESTION_INDEX, questionIndex); dataMap.PutStringArray(Constants.ANSWERS, answers); dataMap.PutInt(Constants.CORRECT_ANSWER_INDEX, correctAnswerIndex); return(request.AsPutDataRequest()); }
public void SendData() { //send data to DataApi layer if (!_client.IsConnected) { return; } PutDataMapRequest mrequest = PutDataMapRequest.Create(syncPath); mrequest.DataMap.PutInt("heartratedata", heartRate); PutDataRequest request = mrequest.AsPutDataRequest(); WearableClass.DataApi.PutDataItem(_client, request); }
/// <summary> /// Handles incoming intents /// </summary> /// <param name="intent">The intent sent by Location Services. This Intent is provided to Location Services (inside a PendingIntent) /// when AddGeofences() is called</param> protected override void OnHandleIntent(Android.Content.Intent intent) { // First check for errors var geofencingEvent = GeofencingEvent.FromIntent(intent); if (geofencingEvent.HasError) { int errorCode = geofencingEvent.ErrorCode; Log.Error(Constants.TAG, "Location Services error: " + errorCode); } else { // Get the type of Geofence transition (i.e. enter or exit in this sample). int transitionType = geofencingEvent.GeofenceTransition; // Create a DataItem when a user enters one of the geofences. The wearable app will receie this and create a // notification to prompt him/her to check in if (transitionType == Geofence.GeofenceTransitionEnter) { // Connect to the Google Api service in preparation for sending a DataItem mGoogleApiClient.BlockingConnect(Constants.CONNECTION_TIME_OUT_MS, TimeUnit.Milliseconds); // Get the geofence ID triggered. Note that only one geofence can be triggered at a time in this example, but in some cases // you might want to consider the full list of geofences triggered string triggeredGeofenceId = geofencingEvent.TriggeringGeofences[0].RequestId; // Create a DataItem with this geofence's id. The wearable can use this to create a notification PutDataMapRequest putDataMapRequest = PutDataMapRequest.Create(Constants.GEOFENCE_DATA_ITEM_PATH); putDataMapRequest.DataMap.PutString(Constants.KEY_GEOFENCE_ID, triggeredGeofenceId); if (mGoogleApiClient.IsConnected) { WearableClass.DataApi.PutDataItem( mGoogleApiClient, putDataMapRequest.AsPutDataRequest()).Await(); } else { Log.Error(Constants.TAG, "Failed to send data item: " + putDataMapRequest + " - disconnected from Google Play Services"); } mGoogleApiClient.Disconnect(); } else if (Geofence.GeofenceTransitionExit == transitionType) { // Delete the data item when leaving a geofence region mGoogleApiClient.BlockingConnect(Constants.CONNECTION_TIME_OUT_MS, TimeUnit.Milliseconds); WearableClass.DataApi.DeleteDataItems(mGoogleApiClient, Constants.GEOFENCE_DATA_ITEM_URI).Await(); mGoogleApiClient.Disconnect(); } } }
private Task SendData (PutDataMapRequest mapReq) { return Task.Run (() => { foreach (var node in clientNodes) { WearableClass.DataApi.PutDataItem (googleApiClient, mapReq.AsPutDataRequest()); } }); }
/** * Transfer the required data over to the wearable * @param attractions list of attraction data to transfer over */ private void SendDataToWearable(List <Attraction> attractions) { GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .AddApi(WearableClass.API) .Build(); // It's OK to use blockingConnect() here as we are running in an // IntentService that executes work on a separate (background) thread. ConnectionResult connectionResult = googleApiClient.BlockingConnect( Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.Seconds); // Limit attractions to send int count = attractions.Count > Constants.MAX_ATTRACTIONS ? Constants.MAX_ATTRACTIONS : attractions.Count; List <DataMap> attractionsData = new List <DataMap>(count); for (int i = 0; i < count; i++) { Attraction attraction = attractions[i]; Bitmap image = null; Bitmap secondaryImage = null; try { //TODO: // Fetch and resize attraction image bitmap //image = Glide.with(this) // .load(attraction.imageUrl) // .asBitmap() // .diskCacheStrategy(DiskCacheStrategy.SOURCE) // .into(Constants.WEAR_IMAGE_SIZE_PARALLAX_WIDTH, Constants.WEAR_IMAGE_SIZE) // .get(); //secondaryImage = Glide.with(this) // .load(attraction.secondaryImageUrl) // .asBitmap() // .diskCacheStrategy(DiskCacheStrategy.SOURCE) // .into(Constants.WEAR_IMAGE_SIZE_PARALLAX_WIDTH, Constants.WEAR_IMAGE_SIZE) // .get(); } catch (Exception e) { Log.Error("UtilityService", "Exception loading bitmap from network"); } if (image != null && secondaryImage != null) { DataMap attractionData = new DataMap(); string distance = Utils.FormatDistanceBetween( Utils.GetLocation(this), attraction.Location); attractionData.PutString(Constants.EXTRA_TITLE, attraction.Name); attractionData.PutString(Constants.EXTRA_DESCRIPTION, attraction.Description); attractionData.PutDouble( Constants.EXTRA_LOCATION_LAT, attraction.Location.Latitude); attractionData.PutDouble( Constants.EXTRA_LOCATION_LNG, attraction.Location.Longitude); attractionData.PutString(Constants.EXTRA_DISTANCE, distance); attractionData.PutString(Constants.EXTRA_CITY, attraction.City); //TODO: // attractionData.PutAsset(Constants.EXTRA_IMAGE, // Utils.CreateAssetFromBitmap(image)); //attractionData.PutAsset(Constants.EXTRA_IMAGE_SECONDARY, // Utils.CreateAssetFromBitmap(secondaryImage)); attractionsData.Add(attractionData); } } if (connectionResult.IsSuccess && googleApiClient.IsConnected && attractionsData.Count > 0) { PutDataMapRequest dataMap = PutDataMapRequest.Create(Constants.ATTRACTION_PATH); dataMap.DataMap.PutDataMapArrayList(Constants.EXTRA_ATTRACTIONS, attractionsData); //TODO: //dataMap.DataMap.PutLong(Constants.EXTRA_TIMESTAMP, DateTime.Now.ToFileTime); PutDataRequest request = dataMap.AsPutDataRequest(); request.SetUrgent(); //TODO: Async/Await // Send the data over // var result = // WearableClass.DataApi.PutDataItem(googleApiClient, request)); // if (!result.).isSuccess()) { // Log.e(TAG, String.format("Error sending data using DataApi (error code = %d)", // result.getStatus().getStatusCode())); // } //} else { // Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG, // connectionResult.getErrorCode())); // } googleApiClient.Disconnect(); } }
private async Task CreateWeatherDataRequest(bool urgent) { // Don't send anything unless we're setup if (!Settings.WeatherLoaded) { return; } if (mWearNodesWithApp == null) { // Create requests if nodes exist with app support mWearNodesWithApp = await FindWearDevicesWithApp(); if (mWearNodesWithApp == null || mWearNodesWithApp.Count == 0) { return; } } PutDataMapRequest mapRequest = PutDataMapRequest.Create(WearableHelper.WeatherPath); var homeData = Settings.HomeData; var weatherData = await Settings.GetWeatherData(homeData.query); var alertData = await Settings.GetWeatherAlertData(homeData.query); if (weatherData != null) { weatherData.weather_alerts = alertData; // location // update_time // forecast // hr_forecast // txt_forecast // condition // atmosphere // astronomy // precipitation // ttl // source // query // locale mapRequest.DataMap.PutString("weatherData", weatherData?.ToJson()); List <String> alerts = new List <String>(); if (weatherData.weather_alerts.Count > 0) { foreach (WeatherData.WeatherAlert alert in weatherData.weather_alerts) { alerts.Add(alert.ToJson()); } } mapRequest.DataMap.PutStringArrayList("weatherAlerts", alerts); mapRequest.DataMap.PutLong("update_time", weatherData.update_time.UtcTicks); PutDataRequest request = mapRequest.AsPutDataRequest(); if (urgent) { request.SetUrgent(); } await WearableClass.DataApi.PutDataItem(mGoogleApiClient, request); Logger.WriteLine(LoggerLevel.Info, "{0}: CreateWeatherDataRequest(): urgent: {1}", TAG, urgent.ToString()); } }