Issue
I want to write a number of html files on my PC. I then want these files bundled into my app installable, so when the app is installed on the smart phone, it already has these files stored locally. I then want to use a button in my existing app to select 1 of these files and then to have this file opened up for viewing in a separate web browser (outside of my app). I have tried using code like this below and it works fine for running html pages from external sites:
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"))
startActivity(browserIntent)
However if I try and publish from a file on my Android like Uri.parse("file://android_assets/test.htm") then my app crashes. Can anyone suggest how I can publish html files from my Android app in a new browser, I would prefer to use something like Intent ACTION_VIEW? I have this working with webview but loading the html page inside the app really degrades the user experience.
Solution
Use FileProvider to create a nice content scheme uri for your html file.
Or if you placed your html files at design time in your project assets folder then your html file is in assets resource when your app runs and you can display it in a WebView component. Webview load html from assets directory
If you do not want to use a WebView in your app use your own FileProvider/ContentProvider to serve files from assets.
You could also copy the file from assets resource to local storage and then use FileProvider with ACTION_VIEW to serve your html.
Answered By - blackapps
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.