android - WearableListenerService - onPeerConnected never called -


i created simple phone<->wear app.

wear app has 1 activity code:

public class mainactivity extends activity implements googleapiclient.connectioncallbacks {  private textview mtextview;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     final watchviewstub stub = (watchviewstub) findviewbyid(r.id.watch_view_stub);     stub.setonlayoutinflatedlistener(new watchviewstub.onlayoutinflatedlistener() {         @override         public void onlayoutinflated(watchviewstub stub) {             mtextview = (textview) stub.findviewbyid(r.id.text);         }     });      getgoogleapiclient(this).connect(); }   private googleapiclient getgoogleapiclient(context context) {     return new googleapiclient.builder(context)             .addapi(wearable.api)             .addconnectioncallbacks(this)             .build(); }  @override public void onconnected(bundle bundle) {      toast.maketext(this, "onconnected", toast.length_short).show(); }  @override public void onconnectionsuspended(int i) {      toast.maketext(this, "onconnectionsuspended", toast.length_short).show(); }} 

and phone app has 1 wearablelistenerservice

public class listenerofconnection extends wearablelistenerservice  {  private static final string tag = "datalayerlistenerservic";   protected googleapiclient googleapiclient; @override public void oncreate() {     super.oncreate();     toast.maketext(listenerofconnection.this, "oncreate", toast.length_short).show();     googleapiclient = new googleapiclient.builder(this)             .addapi(wearable.api)             .build();      googleapiclient.connect(); }   @override public void onpeerconnected(node peer) {     super.onpeerconnected(peer);     toast.maketext(listenerofconnection.this, "onpeerconnected", toast.length_short).show();     logd(tag, "onpeerconnected: " + peer); }  @override public void onpeerdisconnected(node peer) {     super.onpeerdisconnected(peer);     toast.maketext(listenerofconnection.this, "onpeerdisconnected", toast.length_short).show();     logd(tag, "onpeerdisconnected: " + peer); }  public static void logd(final string tag, string message) {     if (log.isloggable(tag, log.debug)) {         log.d(tag, message);     } }} 

the problem onpeerconnected , onpeerdisconnected never called, oncreate not called if not send message.

and if send few messages oncreate called onpeerconnected , onpeerdisconnected never...

before questions me: 1. applicationid same 2. onconnected called on wearable activity

as far can tell, onpeerconnected , onpeerdisconnected events called when app running , bluetooth connection between watch , phone made or broken. in other words, see these events, , virtually never when you're debugging 2 devices sitting on desk.

if you're trying work when app first starts , api-level connection between devices initialized, you'll need use wearable.nodeapi.getconnectednodes method instead.

the documentation stuff less clear...


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -