Android中的信标 - 教程中的错误

Android中的信标 - 教程中的错误

问题描述:

我目前正在使用Android Beacons tutorial,它看起来代码有问题。此方法直接从本教程中复制,但在build()方法后缺少右括号。我尝试过不同的解决方案,但是迄今为止没有成功。Android中的信标 - 教程中的错误

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