EventBus for Android Wear devices.

Related tags

App BusWear
Overview

BusWear - EventBus for Android Wear

Android Arsenal

BusWear logo

BusWear ( 🚌 ⌚ ) is a simple library for EventBus to support Android Wear devices. Just adding one line of code lets you get synchronized event buses on Wear and mobile platform.

Diagram

###What is EventBus?

A great multi-purpose tool for Android apps, way of triggering some events in separate Activity, Fragment, Service etc. EventBus, origin of that project or Otto.

###How to start?

To start with BusWear all you need is to add a dependency. That is it!

###Add BusWear to your project

Gradle:

    //library:
	compile 'com.github.tajchert:BusWear:0.9.6'
    //needed dependency:
    compile 'com.google.android.gms:play-services-wearable:+'

Root build.gradle (due to Jitpack.io):

	allprojects {
		repositories {
			...
			maven { url "https://jitpack.io" }
		}
	}

###How to use?

You can post to remote branch as long as it String, Integer, Long, Short, Float, Double or custom object that implements Parcelable, other "non-Parcelable" objects still can be posted but only locally.

post(object); sends your parcelable object (or String, Integer...) both to local bus and to remote one as well.

postLocal(object) works as old post() of EventBus, it sends event only locally.

postRemote(object) sends your parcelable object (or String, Integer...) to remote bus only.

The same goes for Sticky events - so you get postSticky(), postStickyLocal(), postStickyRemote(). Also methods such removeStickyEvent(Object), removeStickyEvent(Class), removeAllStickyEvents() work in same manner - you get everywhere, remote, local flavours of each method.

###Sample

To send:

EventBus.getDefault(this).post(parcelableObject);     //Custom parcelable object
EventBus.getDefault(this).postRemote("text");         //String
//... similar with Integer, Long etc.
EventBus.getDefault(this).postLocal('c');            //Character - to local function you can pass any object that you like

To receive:

protected void onCreate(Bundle savedInstanceState) {
    EventBus.getDefault(this).register(this);
}

//Called every time when post() is sent (with that particular object), needs to be annotated with the `@Subscribe` annotation.

@Subscribe(threadMode = ThreadMode.MAIN)
public void onMyEvent(ParcelableObject parcelableObject){
    //Do your stuff with that object
}

@Subscribe(threadMode = ThreadMode.MAIN)
public void onMyOtherEvent(String text){
    //Do your stuff with that object
}

//... more onXEvent() with @Subscribe annotation if you want!

###Event propagation

------------------------

------------------------

###Questions?

How is that better than classic EventBus?

EventBus works on mobile na Android Wear - yes, but you got two separate buses, and BusWear gives you a feel of one bus that is shared/synchronized between those two devices.

What are some drawbacks?

Probably quite big one is that all your custom objects to be posted needs to implement Parcelable (or be String, Integer...).

Other one is that you cannot have classes with same name in the same module (for example "wear") - it will lead to errors as matching is done on SimpleName of class.

###License

BusWear binaries and source code can be used according to the Apache License, Version 2.0.

###Thanks

Goes to Polidea for putting me on a project that encouraged me to work on that library, Maciej Górski for Manifest merger, and Dariusz Seweryn for idea with Class name in path String.

Comments
  • BusWear with Parceler

    BusWear with Parceler

     02-23 20:25:15.805    3253-3253/np.pushy D/Event﹕ No local subscribers registered for event class com.neptiun.pushy.event.ButtonClickEvent$$Parcelable
    

    I parceled objects with "Parceler", the infamous parceler library, however, I'm getting no subscribers registered for event.

    Any way possible for them to work together?

    There is too much boilerplate code involved in extending Parceler, would be great if they both worked together?

    Parceler Library Link

    help wanted 
    opened by theshapguy 5
  • Update BusWear with new version of EventBus

    Update BusWear with new version of EventBus

    EventBus 3.0 has been released, update BusWear to use the new version.

    With this update, investigate if EventBus can now be used a dependency vs a full inclusion of the code. This will allow quicker updates as new versions of EventBus are released.

    help wanted 
    opened by btkelly 4
  •  D/BusWearTag﹕ syncEvent error: <init> [class android.os.Parcel]

    D/BusWearTag﹕ syncEvent error: [class android.os.Parcel]

    I have an issue with a simple object Parcelable with just a bundle inside. I use https://github.com/dallasgutauckis/parcelabler I always the same error : D/BusWearTag﹕ syncEvent error: [class android.os.Parcel]

    import android.os.Bundle;
    import android.os.Parcel;
    import android.os.Parcelable;
    public class SimpleDataEvent implements Parcelable{
    
    
        private Bundle mBundle;
    
        public SimpleDataEvent() {
            mBundle = new Bundle();
        }
    
        public SimpleDataEvent(Bundle bundle) {
            this.mBundle = bundle;
        }
    
        ....
    
        public Bundle getBundle() {
            return mBundle;
        }
    
        protected SimpleDataEvent(Parcel in) {
            mBundle = in.readBundle();
        }
    
        @Override
        public int describeContents() {
            return 0;
        }
    
        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeBundle(mBundle);
        }
    
        @SuppressWarnings("unused")
        public static final Creator<SimpleDataEvent> CREATOR = new Creator<SimpleDataEvent>() {
            @Override
            public SimpleDataEvent createFromParcel(Parcel in) {
                return new SimpleDataEvent(in);
            }
    
            @Override
            public SimpleDataEvent[] newArray(int size) {
                return new SimpleDataEvent[size];
            }
        };
    }
    

    Could you help me to find the error. Because your library is very great for simple type. It works very fine, but I need a more complexe object. Thanks for your help.

    opened by trebormat 3
  • Allow service extension

    Allow service extension

    I removed the service declaration from the library manifest file as it did not allow extension of the WearableListenerService (you can only have one). Now users must add the service declaration manually but it allows extension and specific event listening inside the WearableListenerService.

    opened by btkelly 2
  • Receive event without registering

    Receive event without registering

    With the traditional EventBus systems, your app is already running and you have components already registered.

    This library is cool. But my problem is that when I send something from the phone, wear app may not be running at that time. It starts the wear app because of the WearableListenerService inside it. Since there is no registered component at that time, it doesn't do anything. How do you use it in cases like this?

    opened by tasomaniac 2
  • Event Bus 3 update

    Event Bus 3 update

    This is a pretty large PR as there were many changes required to allow EventBus to be included as a dependency instead of being contained inside the library. This is also an update to the latest version of EventBus which transitions to annotated methods instead of the "onEvent" naming convention (resolves #16).

    Note: This will most likely require reimporting the project into Android Studio as there are changes to the iml files. A fresh repo clone may be best but I think a simple reimport would do fine.

    Take a look and if you have feedback, suggestions, modifications please respond and I can make changes accordingly.

    opened by btkelly 1
  • Updated findParcelMethod to handle private and protected constructors

    Updated findParcelMethod to handle private and protected constructors

    This change allows for reflection to locate private and protected Parcel constructors which should resolve #5.

    This also removed the wrapping try catch as I'm guessing that was accidentally included.

    opened by btkelly 1
  • Define `MessagesCatcher` in library and force user to only add it to both Manifests.

    Define `MessagesCatcher` in library and force user to only add it to both Manifests.

    Like so:

    <service android:name="pl.tajchert.buswear.MessagesCatcher">
        <intent-filter>
            <action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
        </intent-filter>
    </service>
    
    opened by mg6maciej 1
  • Moved SendByteArrayToNode size check to constructor

    Moved SendByteArrayToNode size check to constructor

    I moved the byte array size check to the constructor of SendByteArrayToNode allowing an app to fail gracefully if the limit is exceeded. Currently the check happens in the run method which has already been moved to another thread an thus cannot be caught by the existing "Object cannot be sent" log message.

    opened by btkelly 0
  • Ideas to receive Events in a Service ?

    Ideas to receive Events in a Service ?

    Hello everyone, i think this library is an awesome to addition to the regular EventBus. One Problem i stumbled upon is how to replace the WearableListenerService with EventBus. In my Use Case the App on the phone is not necessarily open. So how would you subscribe to a Event, when there is no service instantiated. Especially with the new Android version the Problem arises, because Sticky Services are not allowed anymore.

    Any Suggestions ?

    opened by mjohenneken 0
  • Using gson

    Using gson

    Hi, im new to event bus and i'm willing to try your lib. Im gonna send my objects as strings using google Gson. This prevents the need to implement a parcelable for all my models and provides the same functionality. Maybe you could update your readme with this approach as a possible solution if you like it too.

    opened by sagits 0
  • IncompatibleClassChangeError

    IncompatibleClassChangeError

    This is the stack trace that I got for this error. I have no idea why this is happening. I use the 8.3 play services,

    
    java.lang.IncompatibleClassChangeError: The method 'com.google.android.gms.common.ConnectionResult com.google.android.gms.common.api.GoogleApiClient.blockingConnect(long, java.util.concurrent.TimeUnit)' was expected to be of type interface but instead was found to be of type virtual (declaration of 'java.lang.reflect.ArtMethod' appears in /system/framework/core-libart.jar)
                                                                               at pl.tajchert.buswear.wear.SendByteArrayToNode.run(SendByteArrayToNode.java:36)
    

    But when I use the version 7.5 of the play services it works fine. So I guess the newer play services work differently and the BusWear Lib needs some updates.

    help wanted 
    opened by Aksi0m 2
  • NoSuchMethodError GoogleApiClient.blockingConnect

    NoSuchMethodError GoogleApiClient.blockingConnect

    When I do a EventBus.getDefault().postRemote(...) from my wear module, I get this exception:

    com.google.android.gms.common.api.GoogleApiClient.blockingConnect at pl.tajchert.buswear.wear.SendByteArrayToNode.run(SendByteArrayToNode.java:36)

    I'm using last version of google play services. These are my dependencies in wear build.gradle file:

    compile 'com.google.android.support:wearable:1.3.0' compile 'com.google.android.gms:play-services-wearable:8.4.0' compile 'pl.tajchert:buswear:0.9.5'

    So I don't know where the problem is.

    opened by victordigio 1
  • Not able to send data remotely..

    Not able to send data remotely..

    I have run the sample app.I am facing following exception, any ideas how to resolve this- FATAL EXCEPTION: Thread-357 Process: pl.tajchert.buswear.sample, PID: 5527 java.lang.NoSuchMethodError:com.google.android.gms.common.api.GoogleApiClient.blockingConnect at pl.tajchert.buswear.EventBus$SendByteArrayToNode.run(EventBus.java:796)

    opened by aksatoskar 1
  • Inside Services post / postRemote only post local

    Inside Services post / postRemote only post local

    Code works in Activities, but inside a service both post or postRemote only post to the local event listeners.

    public class WearService extends Service {
        public WearService() {
        }
    
        @Override
        public void onCreate() {
            super.onCreate();
            EventBus.getDefault().register(this);
        }
    
        public void onEvent(Long i) {
            L.e("onEvent:long "+i);
            pushToWear();
        }
    
        public void onEvent(String s) {
            // called after pushToWear!!!!
        }
    
        private void pushToWear() {
         ...
            EventBus.getDefault().postRemote(payload.toString(), this);
        }
    }
    
    opened by paulgavrikov 8
Owner
Michal Tajchert
Mobile Tech Lead, loves Mobile (native&Flutter on daily basis), full stack dev and founder @ Kanarek.app
Michal Tajchert
A free and open-source offline authenticator app for Wear OS.

Wristkey Need 2FA codes quickly, right on your Wear watch without needing a phone? Wristkey is an open-source 2FA client for Wear OS watches that does

Owais Shaikh 80 Jan 4, 2023
HackerNews reader app for Wear OS

HNReader Install by importing to Android Studio, building the apk, and Google the official Android documentation for loading the apps to Wear OS and f

Hikmat Jafarli 2 Sep 4, 2022
SnapChat-Clone - The android studio project for a snapchat clone for android devices

SnapChat-Clone This is the android studio project for a snapchat clone for andro

Ujjwal Sharma 0 Jan 30, 2022
Ankiconnect Android allows you to utilize the standard Anki mining workflow on Android devices like phones and eReaders

Ankiconnect Android Ankiconnect Android allows you to utilize the standard Anki mining workflow on Android devices like phones and eReaders. Create An

Kamron Bhavnagri 29 Dec 28, 2022
Ground Control Station for Android Devices

Tower Tower is a Ground Control Station (GCS) Android app built atop DroneKit-Android, for UAVs running Ardupilot software. Usage Guide The wiki has s

DroidPlanner 593 Dec 30, 2022
Record full-resolution video on your Android devices.

DEPRECATED: Android 11 now includes native screen recording! License Copyright 2015 Jake Wharton Licensed under the Apache License, Version 2.0 (the

Jake Wharton 2.5k Dec 15, 2022
Ground Control Station for Android Devices

Tower Tower is a Ground Control Station (GCS) Android app built atop DroneKit-Android, for UAVs running Ardupilot software. Usage Guide The wiki has s

DroidPlanner 594 Jan 8, 2023
Endoscope lets you to stream live video between android devices over Wi-Fi! 📱📲

Endoscope - RTSP live video streamer for android devices via Wi-Fi. Project is no longer supported. Alternative solution is under development. Stay tu

Przemek 640 Dec 21, 2022
EBT Compass is a compass and GPS app for Android devices.

EBT Compass is a compass and GPS app for Android devices.

Eric Bergman-Terrell 6 Aug 25, 2022
Android library for finding connected devices on same WiFi network. It can provide IP Address, device name, MAC Address and vendor names.

Android WiFi Tools Android library for finding connected devices on the same WiFi network. It can provide IP Addresses, device names, MAC Address and

Tej Magar 5 Nov 16, 2022
Android samples built using Jetpack Window Manager for foldable and dual-screen devices like Microsoft Surface Duo.

Jetpack Window Manager samples for dual-screen and foldable devices like Microsoft Surface Duo Android app samples that use Jetpack Window Manager to

Microsoft 45 Dec 19, 2022
📲💬 react-native-fontext is a lightweight library to integrate fonts in your React Native application that works seamlessly in android and iOS devices.

React Native Fontext react-native-fontext is a lightweight library to integrate fonts in your React Native application that works seamlessly in androi

mroads 9 Dec 3, 2021
Unicopy is an application for Android devices and helps users to copy useful special characters

Unicopy Android Application Unicopy is an application for Android 'Phone' Devices. This helps you to copy and paste some special and complicated Unico

Jacob Lim 1 Oct 28, 2021
Identification of android devices using wallpaper image

WallpaperID The source code of the demo application that calculates an ID for a device using wallpaper images. The ID is scoped to a device and will b

FingerprintJS 20 Sep 27, 2022
Devinfo Patcher is an Android app that marks the inactive slot as successful on devices with a valid `devinfo` partition.

Devinfo Patcher Devinfo Patcher is an Android app that marks the inactive slot as successful on devices with a valid devinfo partition. Usage If the i

Captain Trips 6 Sep 25, 2022
OSGeo4A is a build environment to cross-compile opensource GIS software for android devices

OSGeo4A This provides a set of scripts to build opensource geo tools for Android. This is Experimental Dependencies instructions you need a JDK v8 or

OPENGIS.ch 31 Aug 5, 2022
PhoneAccount Abuse Detector for Android 9.0+ devices

PhoneAccount Abuse Detector Simple application to enumerate and detect any application that (ab)uses adding an indefinite amount of PhoneAccount(s) to

linuxct 96 Dec 2, 2022
This is an open source launcher project for Android devices that has been built completely from scratch

Description This is an open source launcher project for Android devices that has been built completely from scratch. The main goal of this launcher is

OpenLauncher Team 1.3k Dec 21, 2022