在Android应用上集成uber API(深层链接)

时间:2015-12-14 21:34:59

标签: android android-intent deep-linking uber-api

您好我想在我的APP上集成Ride和uber按钮。我通过参数

api请求了
'server_token': 'ma***********************u',
'start_latitude',
'start_longitude',
'end_latitude' 
'end_longitude'. 

我收到了回复:

{
 "result": {
 "prices": [
    {
     "currency_code": "INR",
     "display_name": "uberGO",
    "distance": 18.45,
    "duration": 3503,
    "estimate": "₹559-720",
    "high_estimate": 720,
    "localized_display_name": "uberGO",
    "low_estimate": 559,
    "minimum": 60,
    "product_id": "c8170d76-b67c-44b1-8c26-5f45541434d2",
    "surge_multiplier": 2
  },
  {
    "currency_code": "INR",
    "display_name": "uberGO",
    "distance": 18.45,
    "duration": 3503,
    "estimate": "₹559-719",
    "high_estimate": 719,
    "localized_display_name": "uberGO",
    "low_estimate": 559,
    "minimum": 60,
    "product_id": "bc46ccfe-de64-4cad-b63a-7cf48e649a3e",
    "surge_multiplier": 2
  },
  {
    "currency_code": "INR",
    "display_name": "uberX",
    "distance": 18.45,
    "duration": 3503,
    "estimate": "₹834-1,069",
    "high_estimate": 1069,
    "localized_display_name": "uberX",
    "low_estimate": 834,
    "minimum": 80,
    "product_id": "4da6a747-e0be-4f56-a3c7-3f30f22bf86d",
    "surge_multiplier": 2.4
  },
  {
    "currency_code": "INR",
    "display_name": "uberGO",
    "distance": 18.45,
    "duration": 3503,
    "estimate": "₹834-1,069",
    "high_estimate": 1069,
    "localized_display_name": "uberGO",
    "low_estimate": 834,
    "minimum": 80,
    "product_id": "18656d0e-cc1b-4aa6-8146-92e605626caa",
    "surge_multiplier": 2.4
  },
  {
    "currency_code": "INR",
    "display_name": "uberXL",
    "distance": 18.45,
    "duration": 3503,
    "estimate": "₹1,646-2,099",
    "high_estimate": 2099,
    "localized_display_name": "uberXL",
    "low_estimate": 1646,
    "minimum": 125,
    "product_id": "2ea18da2-bcf0-4df7-a7b8-a827e9945322",
    "surge_multiplier": 3.4
  },
  {
    "currency_code": "INR",
    "display_name": "uberXL",
    "distance": 18.45,
    "duration": 3503,
    "estimate": "₹1,646-2,099",
    "high_estimate": 2099,
    "localized_display_name": "uberXL",
    "low_estimate": 1646,
    "minimum": 125,
    "product_id": "a4404842-e40a-471b-a7a5-13da3551e94f",
    "surge_multiplier": 3.4
    }
  ]
 }
}

现在我在按钮的onclicklisteners上添加了这段代码:

String uri = "uber://?client_id=eFrzgz_2Du2KYUXIi3MKaNOWtxo3i77K&action=setPickup&pickup[latitude]=37.775818&pickup[longitude]=-122.418028&pickup[nickname]=UberHQ&pickup[formatted_address]=1455%20Market%20St%2C%20San%20Francisco%2C%20CA%2094103&dropoff[latitude]=37.802374&dropoff[longitude]=-122.405818&dropoff[nickname]=Coit%20Tower&dropoff[formatted_address]=1%20Telegraph%20Hill%20Blvd%2C%20San%20Francisco%2C%20CA%2094133&product_id=a1111c8c-c720-46c3-8534-2fcdd730040d";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(uri));
startActivity(intent); 


点击这些按钮,它按钮会重定向到具有正确src和dst的超级APP,但它没有选择正确的超级类别,如UberX,UberGo,UberL等。它总是选择默认类别。如何自定义它以使用户只需单击一个按钮即可预订驾驶室。

1 个答案:

答案 0 :(得分:1)

Android的uber-rides-sdk中的深层链接测试所使用的sample data显示了您发送的意图的相同参数,因此它应该有效。

  ?

超级:行动= setPickup&安培; CLIENT_ID =的clientId&安培; PRODUCT_ID =的productId&安培;拾取%5Blatitude%5D = 32.1234&安培;拾取%5Blongitude%5D = -122.3456&安培;拾取%5Bnickname%5D = pickupNick&安培;拾取%5Bformatted_address%5D =拾取%20Address&安培;送货%5Blatitude%5D = 32.5678&安培;送货%5Blongitude%5D = -122.6789&安培;送货%5Bnickname%5D = pickupNick&安培;送货%5Bformatted_address%5D =送货%20Address

在测试数据中,我看到他们还URL/percent encode键和值(例如,拾取%5Blatitude%5D = 32.1234),但是documentation他们不知道。
尝试对数据URI进行编码并重试。

也许你将意图发送给Uber应用程序的时间太晚了?也就是说,在服务器上不再存在产品ID(Uber汽车)之后,Uber应用程序也不会选择它。

这些产品是从sandbox API还是生产API端点返回的?

您是否可以首先通过向GET /v1/products/{product_id}发出请求来验证产品ID,并确保在响应正文中获得200 OK HTTP响应状态代码和正确的产品详细信息?