Uber RideRequestButtonCallback没有被调用。 - Android

时间:2018-01-22 06:29:31

标签: android callback uber-api

我在我的Android应用程序中使用了Uber RideRequestButton。我要做的是将特定product_id(UberGO)的加载信息加载到View.VISIBLE按钮(当前是View.GONE),然后隐藏进度条。

当product_id可用时,一切正常。在回调时,它会正确调用onRideInformationLoaded()。问题是产品ID不可用时。然后调用回调中的所有方法都不会被调用。为什么会这样?即使估算不可用,我仍然想显示按钮。它不应该调用其中一种错误方法吗?

这是我的代码:

RideParameters.Builder rpBuilder = new RideParameters.Builder()
            .setProductId("83941b0d-4be1-4979-a9c0-f0af5ee2b89b")
            .setDropoffLocation(latitude, longitude, dropOffName, dropOffAddress)
            .setPickupToMyLocation();
    requestButton.setRideParameters(rpBuilder.build());
    cabDialog.addView(requestButton);
    requestButton.setVisibility(View.GONE);

    requestButton.setSession(new ServerTokenSession(configuration));
    requestButton.setCallback(new RideRequestButtonCallback() {
        @Override
        public void onRideInformationLoaded() {
            Log.i("Ride Info Loaded", "This method is being called.");
            requestButton.setVisibility(View.VISIBLE);
            pbLoadingUber.setVisibility(View.GONE);
        }

        @Override
        public void onError(ApiError apiError) {
            requestButton.setVisibility(View.VISIBLE);
            pbLoadingUber.setVisibility(View.GONE);
            Log.w("Failed to Get Estimates", apiError.getClientErrors().get(0).getTitle());
        }

        @Override
        public void onError(Throwable throwable) {
            Log.w("Failed to Get Estimates", throwable);
            requestButton.setVisibility(View.VISIBLE);
            pbLoadingUber.setVisibility(View.GONE);
        }
    });
    requestButton.loadRideInformation();

有什么问题?

1 个答案:

答案 0 :(得分:0)

我无法重现您的问题。如果您查看最新的Android Git版本,如果产品ID不存在,您将收到以下错误:

enter image description here

陷入困境的方法是:

@Override
public void onError(ApiError apiError) {
    Toast.makeText(this, apiError.getClientErrors().get(0).getTitle(), Toast.LENGTH_LONG).show();
}

使用以下命令实现“活动”:RideRequestButtonCallback,然后是@Override 3接口方法。

所以你的代码应该是这样的:

public class SampleActivity extends AppCompatActivity implements RideRequestButtonCallback {
...

@Override
protected void onCreate(Bundle savedInstanceState) {

configuration = new SessionConfiguration.Builder()
            .setRedirectUri(REDIRECT_URI)
            .setClientId(CLIENT_ID)
            .setServerToken(SERVER_TOKEN)
            .build();
ServerTokenSession session = new ServerTokenSession(configuration);

RideParameters.Builder rpBuilder = new RideParameters.Builder()
        .setProductId("83941b0d-4be1-4979-a9c0-f0af5ee2b89b")
        .setDropoffLocation(latitude, longitude, dropOffName, dropOffAddress)
        .setPickupToMyLocation();
requestButton.setRideParameters(rpBuilder.build());
requestButton.setSession(session);
requestButton.setCallback(this);
cabDialog.addView(requestButton);
requestButton.setVisibility(View.GONE);

}

@Override
public void onRideInformationLoaded() {
    Toast.makeText(this, "Estimates have been refreshed", Toast.LENGTH_LONG).show();
}

@Override
public void onError(ApiError apiError) {
    Toast.makeText(this, apiError.getClientErrors().get(0).getTitle(), Toast.LENGTH_LONG).show();
}

@Override
public void onError(Throwable throwable) {
    Log.e("SampleActivity", "Error obtaining Metadata", throwable);
    Toast.makeText(this, "Connection error", Toast.LENGTH_LONG).show();
}
}