【发布时间】:2017-12-25 01:51:36
【问题描述】:
我正在开展一个项目,我必须使用 Google 的 Nearby API 在 Raspberry pi3(处理 Android 事物)和 android mobile 之间进行通信。我成功地在树莓派 3 上启动了广告服务,并在移动设备上成功地启动了发现服务。但我无法在我的手机上发现 Raspberry pi3。这是我的代码-
在树莓派3上:
private void startAdvertizing() {
logging("advertizing initiated");
Nearby.Connections.startAdvertising(mCLient,"Tinku",getString(R.string.service_id),mConnectionLifecycleCallback
,new AdvertisingOptions(Strategy.P2P_CLUSTER)).setResultCallback(new ResultCallback<Connections.StartAdvertisingResult>() {
@Override
public void onResult(@NonNull Connections.StartAdvertisingResult startAdvertisingResult) {
if (startAdvertisingResult.getStatus().isSuccess()){
logging("avertizind success");
} else {
logging(startAdvertisingResult.getStatus().getStatusMessage());
}
}
});
}
在移动端:
private void startDicovery() {
Log.d(TAG,"Initializing discovery");
tv.setText("Initializing discovery");
EndpointDiscoveryCallback mEndPointDiscoveryCallback = new EndpointDiscoveryCallback() {
@Override
public void onEndpointFound(String s, DiscoveredEndpointInfo discoveredEndpointInfo) {
Log.d(TAG,"Endpoint found");
tv.setText("Endpoint found");
}
@Override
public void onEndpointLost(String s) {
Log.d(TAG,"Endpoint Lost, "+s);
tv.setText("Endpoint Lost, "+s);
}
};
Nearby.Connections.startDiscovery(mCLient,getString(R.string.service_id),mEndPointDiscoveryCallback,new DiscoveryOptions(Strategy.P2P_CLUSTER))
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()){
logging("Discovert success");
isDiscovery = true;
} else {
logging("Discovery failed "+ status.getStatusMessage());
isDiscovery = false;
}
}
});
}
我不知道我错过了什么。任何帮助将不胜感激。
【问题讨论】:
标签: android google-api raspberry-pi3 android-things google-nearby