正如标题所说,我正在使用android uber sdk为社区反犯罪应用程序。
我的应用程序正在使用Uber SDK来获取Uber的游戏,所以我想实现一个计时器,它会在每个确定的时间将用户位置发送给他的首选联系人。所以我的疑问是,有什么方法可以像'onRequestedRide'那样使用吗?
我希望用户的应用程序要求乘车,在他们确认并且司机确认后,启动计时器以发送位置。
更新
UberTracking.xml
<LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/black">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="request widget"
android:textColor="@color/uber_white"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"/>
<com.uber.sdk.android.rides.RideRequestButton
android:id="@+id/uber_button_white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
uber:ub__style="white" />
</RelativeLayout>
UberTracking.java
public class UberTracking 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 REDIRECT_URI = BuildConfig.REDIRECT_URI;
private static final String SERVER_TOKEN = BuildConfig.SERVER_TOKEN;
private SessionConfiguration configuration;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_uber_tracking);
RideRequestButton uberButtonWhite = (RideRequestButton) findViewById(R.id.uber_button_white);
configuration = new SessionConfiguration.Builder()
.setRedirectUri(REDIRECT_URI)
.setClientId(CLIENT_ID)
.setServerToken(SERVER_TOKEN)
.build();
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();
RideRequestButtonCallback rideRequestButtonCallback = new RideRequestButtonCallback() {
@Override
public void onRideInformationLoaded() {
Toast.makeText(UberTracking.this, "DAMN GOD", Toast.LENGTH_LONG).show();
}
@Override
public void onError(ApiError apiError) {
Toast.makeText(UberTracking.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(UberTracking.this, "Connection error", Toast.LENGTH_LONG).show();
}
};
// This button demonstrates launching the RideRequestActivity (customized button behavior).
// You can optionally setRideParameters for pre-filled pickup and dropoff locations.
RideRequestActivityBehavior rideRequestActivityBehavior = new RideRequestActivityBehavior(this,
WIDGET_REQUEST_CODE, configuration);
uberButtonWhite.setRequestBehavior(rideRequestActivityBehavior);
uberButtonWhite.setRideParameters(rideParametersForProduct);
uberButtonWhite.setSession(session);
uberButtonWhite.setCallback(rideRequestButtonCallback);
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();
}
/**
* 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.getRedirectUri(), String.format(nullError, "Redirect URI"));
checkNotNull(configuration.getServerToken(), String.format(nullError, "Server Token"));
checkState(!configuration.getClientId().equals("insert_your_client_id_here"),
String.format(sampleError, "Client ID"));
checkState(!configuration.getRedirectUri().equals("insert_your_redirect_uri_here"),
String.format(sampleError, "Redirect URI"));
checkState(!configuration.getRedirectUri().equals("insert_your_server_token_here"),
String.format(sampleError, "Server Token"));
}
@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(UberTracking.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(UberTracking.this, "RideRequest error " + error.name(), Toast.LENGTH_SHORT).show();
Log.d(ERROR_LOG_TAG, "Error occurred in the Ride Request Widget: " + error.toString().toLowerCase());
}
}
}
}