Android Open Source - BusWear Send Byte Array To Node






From Project

Back to project page BusWear.

License

The source code is released under:

Apache License

If you think the Android project BusWear listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package pl.tajchert.buswear.wear;
//w  w  w.  j av  a2  s  . c om
import android.content.Context;
import android.util.Log;

import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.wearable.MessageApi;
import com.google.android.gms.wearable.Node;
import com.google.android.gms.wearable.NodeApi;
import com.google.android.gms.wearable.Wearable;

import java.util.concurrent.TimeUnit;


public class SendByteArrayToNode extends Thread {
    private byte[] objectArray;
    private Context context;
    private boolean sticky;
    private Class clazzToSend;

    /**
     * Internal BusWear method, using it outside of library is possible but not supported or tested
     */
    public SendByteArrayToNode(byte[] objArray, Class classToSend, Context ctx, boolean isSticky) {
        objectArray = objArray;
        context = ctx;
        sticky = isSticky;
        clazzToSend = classToSend;
    }

    public void run() {
        if ((objectArray.length / 1024) > 100) {
            throw new RuntimeException("Object is too big to push it via Google Play Services");
        }
        GoogleApiClient googleApiClient = SendWearManager.getInstance(context);
        googleApiClient.blockingConnect(WearBusTools.CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);
        NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
        for (Node node : nodes.getNodes()) {
            MessageApi.SendMessageResult result;
            if (sticky) {
                result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WearBusTools.MESSAGE_PATH_STICKY + clazzToSend.getSimpleName(), objectArray).await();
            } else {
                result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WearBusTools.MESSAGE_PATH + clazzToSend.getSimpleName(), objectArray).await();
            }
            if (!result.getStatus().isSuccess()) {
                Log.v(WearBusTools.BUSWEAR_TAG, "ERROR: failed to send Message via Google Play Services");
            }
        }
    }
}




Java Source Code List

pl.tajchert.buswear.AsyncPoster.java
pl.tajchert.buswear.BackgroundPoster.java
pl.tajchert.buswear.EventBusBuilder.java
pl.tajchert.buswear.EventBusException.java
pl.tajchert.buswear.EventBus.java
pl.tajchert.buswear.HandlerPoster.java
pl.tajchert.buswear.NoSubscriberEvent.java
pl.tajchert.buswear.PendingPostQueue.java
pl.tajchert.buswear.PendingPost.java
pl.tajchert.buswear.SubscriberExceptionEvent.java
pl.tajchert.buswear.SubscriberMethodFinder.java
pl.tajchert.buswear.SubscriberMethod.java
pl.tajchert.buswear.Subscription.java
pl.tajchert.buswear.ThreadMode.java
pl.tajchert.buswear.sample.CustomObject.java
pl.tajchert.buswear.sample.CustomObject.java
pl.tajchert.buswear.sample.MainMobileActivity.java
pl.tajchert.buswear.sample.MainWearActivity.java
pl.tajchert.buswear.util.AsyncExecutor.java
pl.tajchert.buswear.util.ErrorDialogConfig.java
pl.tajchert.buswear.util.ErrorDialogFragmentFactory.java
pl.tajchert.buswear.util.ErrorDialogFragments.java
pl.tajchert.buswear.util.ErrorDialogManager.java
pl.tajchert.buswear.util.ExceptionToResourceMapping.java
pl.tajchert.buswear.util.HasExecutionScope.java
pl.tajchert.buswear.util.ThrowableFailureEvent.java
pl.tajchert.buswear.wear.EventCatcher.java
pl.tajchert.buswear.wear.SendByteArrayToNode.java
pl.tajchert.buswear.wear.SendCommandToNode.java
pl.tajchert.buswear.wear.SendWearManager.java
pl.tajchert.buswear.wear.WearBusTools.java