[英]Beacons in Android - error in tutorial
我目前正在使用Android Beacons教程 ,并且代码似乎有问题。 该方法直接从教程中复制而来,但是build()
方法后缺少右括号。 我尝试了不同的解决方案,但到目前为止没有成功。
private void subscribe() {
if (mSubscribed) {
Log.i(TAG, "Already subscribed.");
return;
}
SubscribeOptions options = new SubscribeOptions.Builder()
.setStrategy(Strategy.BLE_ONLY)
// Note: If no filter is specified, Nearby will return all of your
// attachments regardless of type. You must use a filter to specify
// a particular set of attachments (by type) or to fetch attachments
// in a namespace other than your project's default.
.setFilter(new MessageFilter.Builder()
.includeNamespacedType("some_namespace", "some_type")
.build();
Nearby.Messages.subscribe(mGoogleApiClient, getPendingIntent(), options)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Log.i(TAG, "Subscribed successfully.");
startService(getBackgroundSubscribeServiceIntent());
} else {
Log.e(TAG, "Operation failed. Error: " +
NearbyMessagesStatusCodes.getStatusCodeString(
status.getStatusCode()));
}
}
});
}
感谢您的帮助或建议。
我认为应该有两个build()
调用,一个是MessageFilter.Builder
调用,一个是SubscribeOptions.Builder
调用。
尝试这个:
SubscribeOptions options = new SubscribeOptions.Builder()
.setStrategy(Strategy.BLE_ONLY)
// Note: If no filter is specified, Nearby will return all of your
// attachments regardless of type. You must use a filter to specify
// a particular set of attachments (by type) or to fetch attachments
// in a namespace other than your project's default.
.setFilter(new MessageFilter.Builder()
.includeNamespacedType("some_namespace", "some_type")
.build())
.build();
它适用于具有“无法解析方法订阅...”的人
谢谢提琴手!!!!!!
SubscribeOptions options = new SubscribeOptions.Builder()
.setStrategy(Strategy.BLE_ONLY)
// Note: If no filter is specified, Nearby will return all of your
// attachments regardless of type. You must use a filter to specify
// a particular set of attachments (by type) or to fetch attachments
// in a namespace other than your project's default.
.setFilter(new MessageFilter.Builder()
.includeNamespacedType("some_namespace", "some_type")
.build())
.build();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.