[Solved] Prevent Browser intent object to encoding url

Put your problem here if it does not fit any of the other categories.

[Solved] Prevent Browser intent object to encoding url

Postby shailaja » Thu Mar 15, 2012 7:57 am

Hi

I have the following method to call a browser intent

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private void callBrowser(String srcDir,String filename) {
  2.                 Intent browserIntent = new Intent(Intent.ACTION_VIEW);
  3.                 browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
  4.                 browserIntent.setData(Uri.fromFile(new File(srcDir+File.separator+filename)));
  5.                 browserIntent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
  6.                 startActivity(browserIntent);
  7.                 }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4



and am calling this method using
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. callBrowser(destination, "index.html?session_id="+session_id);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


By using this code i am trying to open a html file (which is there inside sdcard) in browser.

This method is working fine for all urls. But in emulator only. when i test it in device there am getting encoding problem. Means the characters in url which i am passing to browser activity is getting encoded(here i.e from ? to %3f).

at line number 4 in above code, browserintent has been set to encoded data. so the intent object is set to url with encoded characters.

Please help me to avoid url encoding.

Thanks
Shailaja
Last edited by shailaja on Fri Mar 16, 2012 5:26 am, edited 1 time in total.
shailaja
Developer
Developer
 
Posts: 40
Joined: Fri Aug 06, 2010 8:00 am

Top

[Solved] Prevent Browser intent object to encoding url

Postby shailaja » Fri Mar 16, 2012 5:26 am

Hi All,
At last I found the solution for this. I use
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. browserIntent.setData(Uri.withAppendedPath((Uri.fromFile(new File(srcDir+File.separator+filename))), params));
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


instead of
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. browserIntent.setData(Uri.fromFile(new File(srcDir+File.separator+filename)));
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


and i call the browser using
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. callBrowser(destination, "/foldername","index.html?session_id="+session_id);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4



withAppendedPath() is a method in android that Creates a new Uri by appending an already-encoded path segment to a base Uri.

Thanks
Shailaja
shailaja
Developer
Developer
 
Posts: 40
Joined: Fri Aug 06, 2010 8:00 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 18 guests