siggen siggen - 3 months ago 20
Android Question

Beacons in Android - error in tutorial

I'm currently working with the Android Beacons tutorial, and it appears to be something wrong with the code. This method is directly copied from the tutorial, but there is a closing bracket missing after

build()
method. I have tried different solutions, but without success this far.

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()));
}
}
});
}


Thank you for any help or suggestions.

Answer

I think there should be two calls to build(), one for the MessageFilter.Builder and one for the SubscribeOptions.Builder.

Try this:

    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();
Comments