Uber Ride请求按钮示例

时间:2016-07-24 02:14:23

标签: android uber-api

我正在尝试运行优步开发者网站上提供的Uber's Ride Request Button Sample。

然而,我遇到了一些我无法弄清楚的错误。我希望你们能帮忙。

谢谢, CassL

SampleActivity.java

public class SampleActivity extends AppCompatActivity implements RideRequestButtonCallback {

private static final String DROPOFF_ADDR = "One Embarcadero Center, San Francisco";
private static final Double DROPOFF_LAT = 37.795079;
private static final Double DROPOFF_LONG = -122.397805;
private static final String DROPOFF_NICK = "Embarcadero";
private static final String ERROR_LOG_TAG = "UberSDK-SampleActivity";
private static final String PICKUP_ADDR = "1455 Market Street, San Francisco";
private static final Double PICKUP_LAT = 37.775304;
private static final Double PICKUP_LONG = -122.417522;
private static final String PICKUP_NICK = "Uber HQ";
private static final String UBERX_PRODUCT_ID = "a1111c8c-c720-46c3-8534-2fcdd730040d";
private static final int WIDGET_REQUEST_CODE = 1234;

private static final String CLIENT_ID = BuildConfig.CLIENT_ID;
private static final String SERVER_TOKEN = BuildConfig.SERVER_TOKEN;

private RideRequestButton blackButton;
private SessionConfiguration configuration;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);

    configuration = new SessionConfiguration.Builder()
            .setClientId(CLIENT_ID)
            .setServerToken(SERVER_TOKEN)
            .build();

    // Optional: to use the SDK in China, set the region property
    // See https://developer.uber.com/docs/china for more details.
    // configuration.setEndpointRegion(SessionConfiguration.EndpointRegion.CHINA);

    validateConfiguration(configuration);
    ServerTokenSession session = new ServerTokenSession(configuration);

    RideParameters rideParametersForProduct = new RideParameters.Builder()
            .setProductId(UBERX_PRODUCT_ID)
            .setPickupLocation(PICKUP_LAT, PICKUP_LONG, PICKUP_NICK, PICKUP_ADDR)
            .setDropoffLocation(DROPOFF_LAT, DROPOFF_LONG, DROPOFF_NICK, DROPOFF_ADDR)
            .build();

    // This button demonstrates deep-linking to the Uber app (default button behavior).
    blackButton = (RideRequestButton) findViewById(R.id.uber_button_black);
    blackButton.setRideParameters(rideParametersForProduct);
    blackButton.setSession(session);
    blackButton.setCallback(this);
    blackButton.loadRideInformation();

    RideParameters rideParametersCheapestProduct = new RideParameters.Builder()
            .setPickupLocation(PICKUP_LAT, PICKUP_LONG, PICKUP_NICK, PICKUP_ADDR)
            .setDropoffLocation(DROPOFF_LAT, DROPOFF_LONG, DROPOFF_NICK, DROPOFF_ADDR)
            .build();

    // This button demonstrates launching the RideRequestActivity (customized button behavior).
    // You can optionally setRideParameters for pre-filled pickup and dropoff locations.
    RideRequestButton uberButtonWhite = (RideRequestButton) findViewById(R.id.uber_button_white);
    RideRequestActivityBehavior rideRequestActivityBehavior = new RideRequestActivityBehavior(this,
            WIDGET_REQUEST_CODE, configuration);
    uberButtonWhite.setRequestBehavior(rideRequestActivityBehavior);
    uberButtonWhite.setRideParameters(rideParametersForProduct);
    uberButtonWhite.setSession(session);
    uberButtonWhite.loadRideInformation();
}

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

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == WIDGET_REQUEST_CODE && resultCode == Activity.RESULT_CANCELED && data != null) {
        if (data.getSerializableExtra(RideRequestActivity.AUTHENTICATION_ERROR) != null) {
            AuthenticationError error = (AuthenticationError) data.getSerializableExtra(RideRequestActivity
                    .AUTHENTICATION_ERROR);
            Toast.makeText(SampleActivity.this, "Auth error " + error.name(), Toast.LENGTH_SHORT).show();
            Log.d(ERROR_LOG_TAG, "Error occurred during authentication: " + error.toString
                    ().toLowerCase());
        } else if (data.getSerializableExtra(RideRequestActivity.RIDE_REQUEST_ERROR) != null) {
            RideRequestViewError error = (RideRequestViewError) data.getSerializableExtra(RideRequestActivity
                    .RIDE_REQUEST_ERROR);
            Toast.makeText(SampleActivity.this, "RideRequest error " + error.name(), Toast.LENGTH_SHORT).show();
            Log.d(ERROR_LOG_TAG, "Error occurred in the Ride Request Widget: " + error.toString().toLowerCase());
        }
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    AccessTokenManager accessTokenManager = new AccessTokenManager(this);

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_clear) {
        accessTokenManager.removeAccessToken();
        Toast.makeText(this, "AccessToken cleared", Toast.LENGTH_SHORT).show();
        return true;
    } else if (id == R.id.action_copy) {
        AccessToken accessToken = accessTokenManager.getAccessToken();

        String message = accessToken == null ? "No AccessToken stored" : "AccessToken copied to clipboard";
        if (accessToken != null) {
            ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("UberSampleAccessToken", accessToken.getToken());
            clipboard.setPrimaryClip(clip);
        }
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    } else if (id == R.id.action_refresh_meta_data) {
        blackButton.loadRideInformation();
    }

    return super.onOptionsItemSelected(item);
}

/**
 * Validates the local variables needed by the Uber SDK used in the sample project
 * @param configuration
 */
private void validateConfiguration(SessionConfiguration configuration) {
    String nullError = "%s must not be null";
    String sampleError = "Please update your %s in the gradle.properties of the project before " +
            "using the Uber SDK Sample app. For a more secure storage location, " +
            "please investigate storing in your user home gradle.properties ";

    checkNotNull(configuration, String.format(nullError, "SessionConfiguration"));
    checkNotNull(configuration.getClientId(), String.format(nullError, "Client ID"));
    checkNotNull(configuration.getServerToken(), String.format(nullError, "Server Token"));
    checkState(!configuration.getClientId().equals("wOUNMrsBNv_PspfQ16JldsPQx_ryzWpR"),
            String.format(sampleError, "Client ID"));
    checkState(!configuration.getRedirectUri().equals("QO-ROZAvU2BolTewBiwcH7Ww_50yGy8WEJPvYi7w"),
            String.format(sampleError, "Server Token"));
}

}

  

错误:(48,56)错误:找不到符号变量CLIENT_ID   错误:(49,59)错误:找不到符号变量SERVER_TOKEN   :app:compileDebugJavaWithJavac FAILED   错误:任务':app:compileDebugJavaWithJavac'执行失败。   编译失败;请参阅编译器错误输出以获取详细信   07-23 22:05:31.366 15787-15801 /? E / SarMIPIManager:handleMIPI:不匹配,使用默认的MIPI:454   07-23 22:05:31.481 6604-6604 /? E / NetworkScheduler.SR:参数应用程序无效   07-23 22:05:31.481 6604-6604 /? E / NetworkScheduler.SR:包名无效:也许您没有在附加内容中包含PendingIntent?   07-23 22:05:31.486 6592-7340 /? E / com.facebook.katana:MqttOperationManager:operation / add / duplicate; id = -1,name = PINGRESP   07-23 22:05:31.555 4334-5664 /? E / native:暂停false   07-23 22:05:32.651 18830-18840 /? E / DatabaseUtils:向parcel写入异常                                                     java.lang.SecurityException异常:权限拒绝:读取com.android.providers.media.MediaProvider URI内容://媒体/外部/图像/从PID = 16439媒体,UID = 10077要求android.permission.READ_EXTERNAL_STORAGE,或grantUriPermission()                                                         在android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:605)                                                         在android.content.ContentProvider $ Transport.enforceReadPermission(ContentProvider.java:480)                                                         在android.content.ContentProvider $ Transport.query(ContentProvider.java:211)                                                         在android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)                                                         在android.os.Binder.execTransact(Binder.java:453)   07-23 22:05:32.724 16439-18825 /? E / iu.UploadsManager:处理媒体的权限不足                                                         java.lang.SecurityException异常:权限拒绝:读取com.android.providers.media.MediaProvider URI内容://媒体/外部/图像/从PID = 16439媒体,UID = 10077要求android.permission.READ_EXTERNAL_STORAGE,或grantUriPermission()                                                             在android.os.Parcel.readException(Parcel.java:1620)                                                             在android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)                                                             在android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)                                                             在android.content.ContentProviderProxy.query(ContentProviderNative.java:421)                                                             在android.content.ContentResolver.query(ContentResolver.java:491)                                                             在android.content.ContentResolver.query(ContentResolver.java:434)                                                             at ihc.a(PG:112)                                                             在com.google.android.libraries.social.autobackup.FingerprintScannerIntentService.onHandleIntent(PG:82)                                                             在android.app.IntentService $ ServiceHandler.handleMessage(IntentService.java:66)                                                             在android.os.Handler.dispatchMessage(Handler.java:102)                                                             在android.os.Looper.loop(Looper.java:148)                                                             在android.os.HandlerThread.run(HandlerThread.java:61)   07-23 22:06:37.398 16178-16180 /? E / QC-QMI:qmi_client [16178] 9d:无法找到客户端数据   07-23 22:06:37.402 3284-3284 /? E / QC-QMI:qmuxd:fd = 19时的RX返回错误= 0 errno [11:再试一次]   07-23 22:06:37.417 3284-3284 /? E / QC-QMI:在qmux客户端列表中找不到QMUX qmux_client_id = 9d,无法删除   07-23 22:06:37.490 18878-18878 /? E / Diag_Lib:Diag_LSM_Init:无法打开diag驱动程序的句柄,错误= 13   07-23 22:07:50.711 16226-16226 /? E / Spotify:[main @ hgn $ 2:353]应用程序闲置时间过长,停止服务   07-23 22:07:51.101 16226-16226 /? E / Spotify:[main@service.SpotifyService:1100]销毁服务   07-23 22:07:53.433 16226-16226 /? E / Spotify:[main@service.SpotifyService:34067]轨道停止   07-23 22:08:56.584 6592-8800 /? E / fb4a(:):GRAPHQL_QUERY_STRING:尝试设置未知参数' first_notification_stories'关于查询' DeltaNotificationsQuery'   07-23 22:08:57.056 6592-11826 /? E / fb4a(:):GRAPHQL_QUERY_STRING:尝试设置未知参数' first_notification_stories'查询' DeltaNotificationsQuery'

1 个答案:

答案 0 :(得分:1)

您是否编辑了gradle.properties文件?它应该有你自己的CLIENT_ID和SERVER_TOKEN。