0

I'm having a slight problem opening a certain URL in the browser. First of all I use the following code to launch the browser:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Globals.currentChatURL)); 
startActivity(Intent.createChooser(browserIntent, "Select browser:"));

Now if I set Globals.currentChatURL to something like http://www.google.com then it opens that site just fine. But my URL is a little more complicated as it contains multiple parameters which are all base64 encoded. Here is an example of how my URL looks:

http://webportal.mysite.com/ChatProgram/chat.php? intgroup=UFYyMA==&intid=UFYyMEZN&hg=Pw__&pref=user&en=U0NPVFQgTUlMTEFS&ee=cGF1bGdAbWFnbmF0ZWNoLmNvbQ==&eq=UFRWRkVI&ec=TUFHTkFURUNI

Now if I use my above code to try and launch this URL it brings me to the Google search page with the following message:

"Your search - http://URLabove ... did not match any documents"

Yet if I copy the URL and paste it into the address box it brings me to the right place. How can I fix this?? The whole point of this is to have the user click the button and the site to launch, not for the user to have to copy and paste the URL manually.

Any suggestions would be greatly appreciated.

Thanks a lot

PaulG
  • 6,920
  • 12
  • 54
  • 98

1 Answers1

2

There is unwanted equal signs in the query part of your http URI. Such signs have a specific meaning as delimiters in the form &parameter=value. This equal signs represents padding values (0, 1 or 2) from your base64 encoding.

You can either

  • remove them because your base64 server decoder won't bother reconstructing them, or

  • percent encode them (with all other reserved characters).

In android you can use percent encode this way:

String value = URLEncoder.encode("annoying values with reserved chars &=#", "utf-8");
String url = "http://stackoverflow.com/search?q=" + value;

The RFC 2396 is now deprecated but that is what URI.parse() is based on as stated by the documentation:

uriString an RFC 2396-compliant, encoded URI

Community
  • 1
  • 1
pcans
  • 7,611
  • 3
  • 32
  • 27