android - GoogleApiClient onConnected not called on Watch -


i have read thread still faced similar issue:

googleapiclient onconnected never called on wearable device

i tried follow how works: https://developer.android.com/training/wearables/data-layer/events.html

here codes:

public class main extends activity implements dataapi.datalistener, googleapiclient.connectioncallbacks, googleapiclient.onconnectionfailedlistener { private static final string path = "/phonewatch"; private googleapiclient client;  @override protected void oncreate(bundle savedinstancestate) {     log.d("phone watch", "on create!");     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);      client = new googleapiclient.builder(this).addapi(wearable.api).build();     ... }  @override protected void onstart() {     log.d("phone watch", "on start!");      super.onstart();     client.connect(); }  @override protected void onstop() {     log.d("phone watch", "on stop!");      if (client != null && client.isconnected()) {         wearable.dataapi.removelistener(client, this);         client.disconnect();     }      super.onstop(); }  @override public void onconnected(bundle bundle) {     log.d("phone watch", "on connected! add listener.");      wearable.dataapi.addlistener(client, this); }  @override public void onconnectionsuspended(int i) {     log.d("phone watch", "connection suspended."); }  @override public void onconnectionfailed(connectionresult connectionresult) {     log.d("phone watch", "connection failed."); }  @override public void ondatachanged(final dataeventbuffer dataeventbuffer) {     log.d("phone watch", "data changed!"); ... } 

i got this:

07-23 20:07:41.730 24874-24874/virtualgs.phonewatch d/phone watch﹕ on create! 07-23 20:07:41.772 24874-24874/virtualgs.phonewatch d/phone watch﹕ on start!

on connected , other log messages not called. miss anything?

although activity implements googleapiclient.connectioncallbacks , googleapiclient.onconnectionfailedlistener, have never registered activity listener receive callbacks. when building api client, need call following two: addconnectioncallbacks(this) , addonconnectionfailedlistener(this):

client = new googleapiclient.builder(this)     .addapi(wearable.api)     .addconnectioncallbacks(this)     .addonconnectionfailedlistener(this)     .build(); 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -