Search in sources :

Example 1 with DataItemBuffer

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();
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) DataItem(com.google.android.gms.wearable.DataItem) ConnectionResult(com.google.android.gms.common.ConnectionResult) DataItemBuffer(com.google.android.gms.wearable.DataItemBuffer)

Aggregations

ConnectionResult (com.google.android.gms.common.ConnectionResult)1 GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)1 DataItem (com.google.android.gms.wearable.DataItem)1 DataItemBuffer (com.google.android.gms.wearable.DataItemBuffer)1