简体   繁体   中英

Open url with parameters android

Hello I want to open a PayPal uri to pay from android.

And I want to open the web uri and add parmas. How do I do this ?

With an intent like this ?

            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.paypal.com/cgi-bin/webscr"));
            browserIntent.putExtra("param1","param1");
                            browserIntent.putExtra("param2","param2");
                            browserIntent.putExtra("param3","param3");
            startActivity(browserIntent);

You can do that like this.

String params = URLEncoder.encode("param1=param1&param2=param2&param3=param3", "utf-8");
String url = "https://www.paypal.com/cgi-bin/webscr?" + params;

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);

在Android上使用PayPal付款的更简单方法是使用本机PayPal Android SDK

Bishan's solution was not working for me ( = and & were incorrectly encoded).

This is a way to encode a URL with parameters:

Uri authUri = Uri.parse("https://www.paypal.com/cgi-bin/webscr")
                .buildUpon()
                .appendQueryParameter("param1", "value1")
                .appendQueryParameter("param2", "value2")
                .appendQueryParameter("param3", "value3")
                .build();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM