Android - can not access the html file on sdCard

爱⌒轻易说出口 提交于 2020-01-13 05:31:06

问题


I am trying to open html file that I have on my sdCard in Chrome or any other web browser (not html Viewer).

I have tried to enter path to file like this

 file:///storage/extSdCard/page/page.html

I get this error:

 ERR_ACCESS_DENIED

What could be wrong please?

EDIT: I have to mention that I am not developing a android app. I just want to view a html file, that is on my SD card in chrome mobile browser

EDIT2: It is not working from ext. sdcard and also from internal memory

Thank you.


回答1:


This is simply happening because the chrome app doesn't have the permission to read the external storage.
if you need such an app here is a link.
Here is a list of chrome app permissions....

Your accounts

  • find accounts on the device
  • add or remove accounts
  • use accounts on the device
  • read Google service configuration

Your location

  • approximate location (network-based)
  • precise location (GPS and network-based)

Network communication

  • view network connections
  • control Near Field Communication
  • receive data from Internet
  • full network access

Storage

  • modify or delete the contents of your USB storage

System tools

  • test access to protected storage
  • install shortcuts

Bookmarks and History

  • write web bookmarks and history
  • read your Web bookmarks and history

Camera

  • take pictures and videos

Microphone

  • record audio

Affects battery

  • prevent device from sleeping
  • control vibration

Audio settings

  • change your audio settings

Sync Settings

  • read sync statistics
  • toggle sync on and off
  • read sync settings



回答2:


I had the same problem and the only way I found to solve the problem of reading the html file in Chrome in a device that isn't rooted is to copy or move the html file into the device's internal memory storage.

The alternative is to root the device and change the permissions to allow sdCard access in Chrome.




回答3:


One way to work around was (on a device with a side loaded chrome)

adb shell pm grant com.chrome.canary android.permission.READ_EXTERNAL_STORAGE

"com.android.chrome" might be the name if you aren't using canary version of chrome.




回答4:


I needed to do the same for my own website. I did not want to look up my website on the internet, because I would get charged by google adwords for clicking on it. I copied the files of my website (index.html and all the folders) to the Internal Storage Download folder, in a folder mywebsite.com that I created. In the Chrome browser, I typed the following:

file://com.estrongs.files/storage/emulated/0/Download/mywebsite.com/index.html

The website opened up perfectly with all the linked pages and images. I then bookmarked it as a favorite so I don't have to type the long url again. The directory structure I show is on my Samsung Android phone. It may be different on another android or iphone. The key is that the website files need to be on internal storage and not on the SD Card as Chrome does not have permission to access external storage.




回答5:


Upload your html files into any app's internal file directory. I added my file to default browser app's directory.

And type the following url in your browser:

file:///storage/sdcard/Android/data/com.android.browser/files/yourfile.html

It should be successfully rendering the web page.



来源:https://stackoverflow.com/questions/21675758/android-can-not-access-the-html-file-on-sdcard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!