我目前正在使用Android Beacons tutorial,但代码似乎有问题。此方法直接从教程中复制,但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()));
}
}
});
}
感谢您提供任何帮助或建议。
答案 0 :(得分:3)
我认为应该有两次拨打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();
答案 1 :(得分:0)
对于拥有&#34;无法解决方法订阅的人来说,它有效...&#34;
向Fiddler !!!!!!
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();