Android 安卓wear can´;不要给电话发信息
我一直在跟踪从安卓wear向安卓手机发送消息,但它不起作用。这是我的代码: 磨损 首先,我实现了google play services元数据,如下所示:Android 安卓wear can´;不要给电话发信息,android,wear-os,google-datalayer,wearables,Android,Wear Os,Google Datalayer,Wearables,我一直在跟踪从安卓wear向安卓手机发送消息,但它不起作用。这是我的代码: 磨损 首先,我实现了google play services元数据,如下所示: <meta-data android:name="com.google.android.wearable.standalone" android:value="true" /> <meta-data android:name="com.google.android.gms.ver
<meta-data
android:name="com.google.android.wearable.standalone"
android:value="true" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
googleClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
@Override
public void onConnected(Bundle connectionHint) {
System.out.println("SESSION CONNECTED");
}
// Disconnect from the data layer when the Activity stops
@Override
protected void onStop() {
if (null != googleClient && googleClient.isConnected()) {
googleClient.disconnect();
}
super.onStop();
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
protected void onStart() {
super.onStart();
googleClient.connect();
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
System.out.println("FAILED TO CONNECT: "+connectionResult.getErrorMessage());
}
然后,我实现了接口所需的所有方法:GoogleAppClient.ConnectionCallbacks和
GoogleAppClient.OnConnectionFailedListener,如下所示:
<meta-data
android:name="com.google.android.wearable.standalone"
android:value="true" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
googleClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
@Override
public void onConnected(Bundle connectionHint) {
System.out.println("SESSION CONNECTED");
}
// Disconnect from the data layer when the Activity stops
@Override
protected void onStop() {
if (null != googleClient && googleClient.isConnected()) {
googleClient.disconnect();
}
super.onStop();
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
protected void onStart() {
super.onStart();
googleClient.connect();
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
System.out.println("FAILED TO CONNECT: "+connectionResult.getErrorMessage());
}
最后,我实现了向手机发送文本的功能:
NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleClient).await();
for (Node node : nodes.getNodes()) {
MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(googleClient, node.getId(), path, message.getBytes()).await();
if (result.getStatus().isSuccess()) {
System.out.println("Message: {" + message + "} sent to: " + node.getDisplayName());
}
else {
// Log an error
System.out.println("ERROR: failed to send Message");
}
}
问题是,它似乎可以工作(当我开始佩戴时,我得到了“会话连接”字符串),但它找不到任何配对的设备来发送字符串,因为节点列表是空的。这可能是模拟器的问题吗?手机和佩戴都可能无法同步,因此它们无法找到对方
电话
为了展示这个洞的例子,我还包括了手机部分:
Manifest.xml
<service android:name=".utils.ListenerService">
<intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER"
tools:ignore="WearableBindListener" />
</intent-filter>
</service>
好吧,不管怎样,这是模拟器的问题,它们没有同步。只是用真正的设备进行了尝试,它就成功了。我的问题是,手机上的应用程序和手表上的应用程序使用不同的证书签名,尽管它们有相同的appid