android - onMessageReceived() never called, although connected to handheld -


i want send messages handheld device smartwatch (moto360) when message comes up.

i made sure both modules have same package name, debug.key , version number.

the listener gets added in onconnected() , function called.

here handheld gradle.build:

apply plugin: 'com.android.application'  android { compilesdkversion 19 buildtoolsversion "22.0.0"  defaultconfig {     applicationid "de.bachelorthesis.important"     minsdkversion 9     targetsdkversion 19     versioncode 1     versionname "1.0" }  signingconfigs {     debug {         storefile file("../debug.keystore")     } }  buildtypes {     release {         minifyenabled false         proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.txt'     }   } }  dependencies { compile 'com.android.support:support-v4:19.1.0' compile 'com.google.android.gms:play-services:7.0.0' compile files('libs/commons-io-2.4.jar') compile files('libs/mapquest-android-sdk-1.0.5.jar') compile files('libs/osmdroid-android-4.2.jar') compile files('libs/slf4j-android-1.7.7.jar') wearapp project(':wear') 

}

in handheld activity message should sent this:

 private void sendtosmartwatch(msg) {     final string msg_arg = msg;      new thread(new runnable() {         public void run() {              mgoogleapiclient = new googleapiclient.builder(getbasecontext())                     .addapi(wearable.api)                     .build();              connectionresult connectionresult =                     mgoogleapiclient.blockingconnect(5, timeunit.seconds);              nodeapi.getlocalnoderesult nodes =                     wearable.nodeapi.getlocalnode(mgoogleapiclient).await(3, timeunit.seconds);               com.google.android.gms.wearable.node node = nodes.getnode();              messageapi.sendmessageresult result = wearable.messageapi.sendmessage(                     mgoogleapiclient, node.getid(), constant, msg_arg.getbytes()).await();             log.d("node:result: ", "" + result.getstatus());               if (result.getstatus().issuccess()) {                 // log success             }             else {                 // log error             }              mgoogleapiclient.disconnect();         }     }).start(); } 

the wearable gradle.build file looks this:

apply plugin: 'com.android.application'  android { compilesdkversion 22 buildtoolsversion "22.0.0"  defaultconfig {     applicationid "de.bachelorthesis.important"     minsdkversion 20     targetsdkversion 22     versioncode 1     versionname "1.0" }  signingconfigs {     debug {         storefile file("../debug.keystore")     } }  buildtypes {     release {         minifyenabled false         proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro'     } } }  dependencies { compile filetree(include: ['*.jar'], dir: 'libs') compile 'com.google.android.support:wearable:1.1.0' compile 'com.google.android.gms:play-services-wearable:+' compile 'com.google.android.gms:play-services:+' compile 'com.android.support:support-v4:22.0.0' } 

and eventually, message should come here on watch:

public class mainactivity extends activity implements googleapiclient.connectioncallbacks,     googleapiclient.onconnectionfailedlistener {  ...  oncreate(){  mgoogleapiclient = new googleapiclient.builder(getapplicationcontext())             .addapi(wearable.api)             .addconnectioncallbacks(this)             .addonconnectionfailedlistener(this)             .build();     mgoogleapiclient.connect(); }  mlistener = new messageapi.messagelistener() {         @override         public void onmessagereceived(messageevent messageevent) {             if (messageevent.getpath().equals(constant)) {                 //do stuff message             }          }     };  }   @override public void onconnected(bundle bundle) {     wearable.messageapi.addlistener(mgoogleapiclient, mlistener); } 

i have tried several different listeners listenerservice (also bind_listener in manifest.xml)

also have tried phoneservice class from answer.

any suggestions doing wrong?

edit: forgot mention message gets sent handheld successfully, not received.

edit 2: issue, handheld module has name "app" instead of "mobile"?! project migrated eclipse, add wearable feature.

so, figured out myself:

this project helping.

i think constants made difference. no path, randomly set constant me. still not sure, tho.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -