Android Question Why is webview not working from subfolder in dirinternal

omo

Active Member
Licensed User
Longtime User
In SMM, why is webview not working from subfolder as in code line below using:

'..File.Copy(file.dirasset, "faq.html", xui.DefaultFolder, "myalbum/" & "faq.html")

MediaManager.SetMediaFromFile(pnl,xui.DefaultFolder, "myalbum/" & "faq.html","text/*",Null)

NOTE:
All necessary files were already copied successfully to subfolder and loading other files like video, audio, image from same subfolder work perfectly, only webview is problematic
Also, there is no problem loading SMM-webview files directly from dirasset, problem is only from dirinternal/xui.DefaultFolder subfolders

ERROR INFO:
All attempts keep giving this error:

Webpage not available
The webpage at file:///data/user/0/b4a.exampleb4xt2/files/myalbum%2Ffaq.html could not be loaded because:

net::ERR_ACCESS_DENIED

MY ATTEMPT SO FAR:

In the manifest, i put at different time with no success:

1st:
AddPermission("android.permission.INTERNET")

2nd:
At another time, since the subfolder is dirinternal/xui.DefaultFolder; WRITE/READ_EXTERNAL_STORAGE is not necessary. However, to avoid doubt; i still used it to no avail and also used:

SetApplicationAttribute(android:requestLegacyExternalStorage, true)

3rd:
I modified MediaManager to different things like below, but same problem persisted:

MediaManager.SetMediaFromFile(pnl,$"${xui.FileURI(xui.DefaultFolder, "myalbum/"& "faq.html")}"$,"text/*",Null)

MediaManager.SetMediaFromFile(pnl,xui.DefaultFolder,File.Combine(xui.DefaultFolder, "myalbum/" & "faq.html"),"text/*",Null)

MediaManager.SetMediaWithExtra(pnl,"file:///"&File.DirInternal&"/"&"myalbum/" & "faq.html","text/*",Null)

pnl.GetView(1).GetView(0).As(WebView).LoadUrl(xui.FileURI(xui.DefaultFolder, "myalbum/" & "faq.html"))

All other files work except webview not displayed

res22.jpg
 

drgottjr

Expert
Licensed User
Longtime User
the file:/// scheme only works for assets and res.
 
Last edited:
Upvote 0

omo

Active Member
Licensed User
Longtime User
the file:/// scheme only works for assets.
Thank you @ drgottjr; yes, I know, but since I was left with no other option that was why i tried as seen above thus:
MediaManager.SetMediaWithExtra(pnl,"file:///"&File.DirInternal&"/"&"myalbum/" & "faq.html","text/*",Null)

I have tried different options as explained above with no success working with dirinternal. I don't have problem working with asset, but the problem I want to solve is that of dirinternal, I don't know while non of my attempts failed to work
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
the file:/// scheme does not work with dirinternal with a webview. in spite of this, you use it.

although the file:/// scheme does not work, you can use webview.loadhtml(file.readstring(folder,file))
as an alternative. in this scenario, you can have sub-filders, but you will face problems when you try to
load resources from within an html document in a webview.

in theory, webviewassetloader is supposed to work, but i don't think it supports sub-folders.

forum member ivica golubovic has a workaround that might be helpful, but you'll have to find it. it's more
of a snippet than a library, and i don't believe he incorporporated it into any of his libraries. speaking of which,
i think he has a webviewassetloader library. could be worth a try.
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
the file:/// scheme does not work with dirinternal with a webview. in spite of this, you use it.

although the file:/// scheme does not work, you can use webview.loadhtml(file.readstring(folder,file))
as an alternative. in this scenario, you can have sub-filders, but you will face problems when you try to
load resources from within an html document in a webview.

in theory, webviewassetloader is supposed to work, but i don't think it supports sub-folders.

forum member ivica golubovic has a workaround that might be helpful, but you'll have to find it. it's more
of a snippet than a library, and i don't believe he incorporporated it into any of his libraries. speaking of which,
i think he has a webviewassetloader library. could be worth a try.
As in my question, I am not talking about ordinary webview. I am talking about the embedded webview in SMM (Simple Media Manager). Video, image, audio work from the same subfolder, but only the embedded webview in SMM fails to work from same subfolder as shown in the image. And I remember, I also used file.readstring during my attempt though not included above. All of them work with asset, but failed with dirinternal subfolder
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
I still don't understand why any of my attempt did not work out on SMM-webview subfolder in dirinternal. What did I do wrong?
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
As webview is a webview. Just because it is embedded in SMM doesn't mean that it will work any differently and hence
@drgottjr explaination is valid.
If you check my question in #1 above, I have tried several attempts including what drgott suggested before comming to the forum to ask, but all didn't work with subfolder in dirinternal. As I said in #1, I don't have problem working with dirasset, it works well with dirasset, but what I need is to work from subfolder in dirinternal. I will be happy if you have a small sample that works with subfolder in dirinternal. All other files like video, audio, animation, image,PDF work from same subfolder in dirinternal with SMM, only webview file failed to work.
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
Edit:

It seems it doesn't like targetSdkVersion > 29
Thank you Eric for your suggestion, although; I never attempted lowering targetSdkversion. I may try it for fun. However, if I lower it from 33; it will be of no use to me because the application must meet current SDKtarget 33. I tested my series of my attempts with Android 14 and Android 9, webview failed to read HTML files from subfolder in dirinternal while reading of video, audio, pdf, images work very well with smm from same subfolder in dirinternal
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
It only works if you change targetSdkVersion to 29 and it doesn't matter as it will also not work without subfolders. As explained by drgottjr it is about Google blocking the use of file:// scheme. I think little we can do about it.
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
It only works if you change targetSdkVersion to 29 and it doesn't matter as it will also not work without subfolders. As explained by drgottjr it is about Google blocking the use of file:// scheme. I think little we can do about it.
Ok, thank you for the info. The app will be published to google play, i think lowering to targetSdkVersion to 29 will not help here based on google rule.
 
Upvote 0
Top