2016-12-22 68 views
3

優步應用程序打開,但沒有在相應字段中設置取件和取件位置。代碼和uri從https://developer.uber.com/docs/riders/ride-requests/tutorials/deep-links/introduction#android client_id獲得我自己的。優步深度Android應用程序

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

嘗試通用鏈接,將重定向到超級應用程序 – Qamar

回答

0

需要爲字符串應用網址編碼。對於示例:

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";