'Cannot open file:// URLs on Android
I'm trying to make my Python script open a local HTML file in the browser, or at least in web view, on Android (app Pydroid3).
Given that I specified the filename in filename:
# method 1
import webbrowser, os
webbrowser.open("file://"+os.path.realpath(filename))
This results in the message:Cannot open file:// URLs on Android.
I am unable to find the first error as a sentence in a web search, is this error this uncommon?
When I un-quoted it I found only this other proposal:
# method 2
from urllib.request import pathname2url
url = 'file:{}'.format(pathname2url(os.path.abspath(filename)))
webbrowser.open(url)
This results in a toast stating:Unable to start activity for android.intent.action.VIEW/file:/storage/emulated/0/folder/filename.html
How can I make it work?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
