use of com.google.android.gms.wearable.DataItemBuffer in project muzei by romannurik.
the class ArtworkCacheIntentService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).build();
ConnectionResult connectionResult = googleApiClient.blockingConnect(30, TimeUnit.SECONDS);
if (!connectionResult.isSuccess()) {
Log.e(TAG, "Failed to connect to GoogleApiClient: " + connectionResult.getErrorCode());
return;
}
// Read all DataItems
DataItemBuffer dataItemBuffer = Wearable.DataApi.getDataItems(googleApiClient).await();
if (!dataItemBuffer.getStatus().isSuccess()) {
Log.e(TAG, "Error getting all data items: " + dataItemBuffer.getStatus().getStatusMessage());
}
Iterator<DataItem> dataItemIterator = dataItemBuffer.singleRefIterator();
boolean foundArtwork = false;
while (dataItemIterator.hasNext()) {
DataItem dataItem = dataItemIterator.next();
foundArtwork = foundArtwork || processDataItem(googleApiClient, dataItem);
}
dataItemBuffer.release();
if (foundArtwork) {
// Enable the Full Screen Activity and Artwork Complication Provider Service only if we've found artwork
enableComponents(FullScreenActivity.class, ArtworkComplicationProviderService.class);
}
if (!foundArtwork && intent != null && intent.getBooleanExtra(SHOW_ACTIVATE_NOTIFICATION_EXTRA, false)) {
ActivateMuzeiIntentService.maybeShowActivateMuzeiNotification(this);
} else {
ActivateMuzeiIntentService.clearNotifications(this);
}
googleApiClient.disconnect();
}
Aggregations