Android Question Open html file from dirassets (internal)

trepdas

Active Member
Licensed User
Hello Good People,

in my current project I need to open a single html file (which is sitting in the dir assets) with the device's default browser.

I added reference to phone lib and tried the following :


B4X:
Dim pi As PhoneIntents

StartActivity (pi.OpenBrowser (File.DirAssets,"page.html"))

obviously, not working.

can anyone advice me how to make this work?

also,the app will be mainly used in amazon's kindle devices so I need a solution to work on that too.
 

JohnC

Expert
Licensed User
Longtime User
Since you want an external program (the device's browser) to be able to access a file that your app is providing, you need to:

1) Copy it from the .DirAssets to a Shared directory.
2) Use the below lib to allow the file to be accessible from external apps.

 
Upvote 0

kisoft

Well-Known Member
Licensed User
Why in the browser? You can do this with webview...
B4X:
    Dim xui As XUI
    Dim WebView1 As WebView
    WebView1.LoadUrl(xui.FileUri(File.DirAssets,"page.html"))
 
Upvote 0

trepdas

Active Member
Licensed User
because the internal file contains an affiliate link and will be effective only with the default browser's cookies... :/


but, if the webview will open the url with the default browser...that can be helpful..
 
Upvote 0

trepdas

Active Member
Licensed User
Since you want an external program (the device's browser) to be able to access a file that your app is providing, you need to:

1) Copy it from the .DirAssets to a Shared directory.

like this?
File.Copy(File.DirAssets, "page.html", File.Dirinternal, "page.html")
is it mandatory to copy it? can't I ask the default browser to read the file directly from dirassets?
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
No, the fileprovider lib code that I linked to has a routine that will return a "Shared" directory for you to use. That is the directory that you need to copy the file into.

Yes, it is mandatory that you use this shared directory and this file-provider method if you want an external program (the device's default browser) to be able to access it.
 
Last edited:
Upvote 0
Top