Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch browser to open local file

Tags:

android

I'm trying to send intent to browser to open local file. I wish to use default browser to open this file.

if(file.exists()){
  Log.d(TAG, "file.exists");
  Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file));
  context.startActivity(intent);
}

But it throws me and exeption

08-10 13:27:58.993: ERROR/AndroidRuntime(28453): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///sdcard/release_notes.htm }

If I use following intent browser opens google.com as expected

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com"));

Also when I write the file url (file:///sdcard/release_notes.htm) to browser address bar it opens it as expected.

like image 969
roose Avatar asked Aug 10 '11 10:08

roose


People also ask

How do I make a file open in browser instead of downloading?

To make certain file types OPEN on your computer, instead of Chrome Downloading... You have to download the file type once, then right after that download, look at the status bar at the bottom of the browser. Click the arrow next to that file and choose "always open files of this type". DONE.

How to open local files on your browser in Windows?

How to Open Local Files on Your Browser in Windows 1 Preamble – Security Issues. There are a few issues that need to be addressed before you access local files in your browser. ... 2 Google Chrome. Using Google Chrome to access local files is as easy as pressing Ctrl + O at the same time. ... 3 Firefox. ... 4 Edge. ... 5 Wrapping Up. ...

How do I add the local Explorer extension to my browser?

To add the Local Explorer extension to a Chromium browser, which enhances the file navigator, click the Add to Chrome button on that add-on’s page. Press the Add extension button to confirm. Thereafter, a Local Explorer page will open on which you’ll need to click the Add to Windows Explorer button.

How do I access local files in Google Chrome?

Using Google Chrome to access local files is as easy as pressing Ctrl + O at the same time. This interface will open, allowing you to navigate to whichever file or folder is needed.

Why can't I open local files in my computer?

Depending on the browser, opening the local files is either natively supported or requires a slight modification of the settings on your computer. There are a few issues that need to be addressed before you access local files in your browser. Since the browser has complete access to the Internet, security is the most important.


1 Answers

The browser is started only for HTML and other compatible files. this should work:

Intent intent = new Intent(ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "text/html");
like image 53
rds Avatar answered Oct 16 '22 18:10

rds