Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Open Browser with Supplied Session Cookie

I'm currently looking for a way to launch the default browser application on Android and pass a session cookie to it.

My application communicates with an external API over which I have no control using HttpClient, then passes the user to the site for the final stages.

I am aware that this is probably possible using a WebView, However I very specifically need to open the external browser application rather than using an internal WebView.

I know that:

Intent.ACTION_VIEW

Can be used to open the browser, however I have not managed to find much information about actually passing any additional data through.

Any help is much appreciated.

like image 950
rblk Avatar asked Aug 26 '10 09:08

rblk


2 Answers

I'm currently looking for a way to launch the default browser application on Android and pass a session cookie to it.

This is not possible, sorry.

like image 82
CommonsWare Avatar answered Sep 20 '22 05:09

CommonsWare


Do you know url-rewrite? It will help you achieve your demand. A url-write may be like this: "http://localhost:8080/test/error.jsp;jsessionid=C4E6732EBB4C17F409AB41143735C096".

The "jsessionid" is the key for sessionid, and C4E6732EBB4C17F409AB41143735C096 is the value. The key to represent the sessionid attribute is different depends on what language is used in the web projects.

So, if you want to keep the session, you can launch the default like this:

    Uri uri = Uri.parse("http://localhost:8080/test/error.jsp;jsessionid=C4E6732EBB4C17F409AB41143735C096");
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(intent);

the sessionid you can get from the HttpClient, and just add it behind your url.

There are also some problems that need to pay attention. First, in the url, the separator is ";" not "?", because the sessionid is in http header, not the http body. Second, if the browser already has a session with the server, then the url-rewrite won't work because the browser will use the its own session, to solve this, you can use you app to get the browser's session and use this session in the HttpClient.

like image 41
Sam Avatar answered Sep 20 '22 05:09

Sam