优步应用程序已打开,但未在相应字段中设置取件和下车位置。代码和uri来自我自己的https://developer.uber.com/docs/riders/ride-requests/tutorials/deep-links/introduction#android client_id。
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
PackageManager pm = this.getPackageManager();
pm.getPackageInfo("com.ubercab", PackageManager.GET_ACTIVITIES);
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);
} catch (PackageManager.NameNotFoundException e) {
// No Uber app! Open mobile website.
}
}
}
答案 0 :(得分:0)
需要对字符串应用url编码。样本:
String uri = "uber://?client_id=eFrzgz_2Du2KYUXIi3MKaNOWtxo3i77K&action=setPickup&pickup[latitude]=37.775818&pickup[longitude]=-122.418028&pickup[nickname]=UberHQ&pickup[formatted_address]="+ URLEncoder.encode("1455 Market St, San Francisco, CA 94103", "UTF-8")+"&dropoff[latitude]=37.802374&dropoff[longitude]=-122.405818&dropoff[nickname]=Coit+Tower&dropoff[formatted_address]="+URLEncoder.encode("1 Telegraph Hill Blvd, San Francisco, CA+94133", "UTF-8")+"&product_id=a1111c8c-c720-46c3-8534-2fcdd730040d";