我正在使用Eclipse IDE开发Android Wear应用程序。我为Wear应用程序和移动应用程序使用相同的包名称,并根据Google文档手动打包可穿戴应用程序。一切正常,通过USB调试安装在Android Wear模拟器上。
我的问题是,当我使用以下代码向可穿戴设备发送消息时:
List<Node> nodeList=getNodes();
for(Node node : nodeList) {
Log.v(" ", "telling " + node.getId() );
PendingResult<MessageApi.SendMessageResult> result = Wearable.MessageApi.sendMessage(
mGoogleApiClient,
node.getId(),
START_ACTIVITY_PATH,
null
);
result.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
@Override
public void onResult(MessageApi.SendMessageResult sendMessageResult) {
Log.v(" ", "Phone: " + sendMessageResult.getStatus().getStatusMessage());
}
});
}
在 WearableListenerService 中,当设备建立对等连接时,OnPeerConnected 方法会运行,但是 OnMessageReceived 从未被调用。这是我的 WearableListenerService 代码:
public class DataLayerListenerService extends WearableListenerService {
private static final String TAG = "DataLayerSample";
private static final String START_ACTIVITY_PATH = "/start/MainActivity";
private static final String DATA_ITEM_RECEIVED_PATH = "/data-item-received";
private static final String LOG_TAG = "log";
@Override
public void onPeerConnected(Node peer) {
super.onPeerConnected(peer);
String id = peer.getId();
String name = peer.getDisplayName();
Log.d(LOG_TAG, "Connected peer name & ID: " + name + "|" + id);
}
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
System.out.println("Recevive message3");
}
@Override
public void onMessageReceived(MessageEvent messageEvent) {
System.out.println("service watch message1");
if (messageEvent.getPath().equals(START_ACTIVITY_PATH)) {
System.out.println("service watch message2");
Intent startIntent = new Intent(this, MainActivity.class);
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startIntent);
}
}
}
同时在Logcat中,总是出现一个警告信息:
应用不匹配记录的应用密钥:AppKey [com.myapp,c3f31717fa35401056c20a2798907f1232efa75e]!= AppKey [com.myapp,f36e726eefc7e528db26a1c25f6fbf2f93dacd70]
如果两个应用程序的应用密钥应该相同,那么我如何为两个应用程序创建相同的应用密钥。
非常感谢任何帮助,谢谢。
com.myphoneapp
和com.wearableapp
是什么? - Maciej Ciemięga