Android Question File.DirAssets returns AssetsDir as string text

MicroDrie

Well-Known Member
Licensed User
I use B4A version 9.50 and B4A Bridge version 2.60. I am having problems with the Log command ("DirAssets:" & File.DirAssets). This returns the string text "DirAssets: AssetsDir".

B4X:
    Log("DirAssets: " & File.DirAssets)
    Log("DirDefaultExternal: " & File.DirDefaultExternal)
    Log("DirRootExternal: " & File.DirRootExternal)
    Log("DirInternal: " & File.DirInternal)
    Log("DirInternalCache: " & File.DirInternalCache)

The result is:
Logger connected to: samsung SM-J730F
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
DirAssets: AssetsDir
DirDefaultExternal: /storage/emulated/0/Android/data/b4a.example/files
DirRootExternal: /storage/emulated/0
DirInternal: /data/user/0/b4a.example/files
DirInternalCache: /data/user/0/b4a.example/cache
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Service (starter) Destroy (ignored)**
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **


How can I solve this challenge so that I get the correct memory location from the Assets directory is returned?
 

DonManfred

Expert
Licensed User
Longtime User
It is not relevant. It depends on which sdcard the app is installed (internal or external).

If you want to access a file in the Filesdir you should use File.DirAssets.

What are you trying to archieve?
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
I load an html file into a webview element to insert once loaded information.
B4X:
    Log("DirAssets: " & File.DirAssets)
   Log("DirDefaultExternal: " & File.DirDefaultExternal)
   Log("DirRootExternal: " & File.DirRootExternal)
   Log("DirInternal: " & File.DirInternal)
   Log("DirInternalCache: " & File.DirInternalCache)
       
   If FirstTime = True Then
       If File.Exists(File.DirDefaultExternal,"*.html") = False Then
           File.Copy(File.DirAssets,"index.html", File.DirDefaultExternal,"index.html")
           File.Copy(File.DirAssets,"style.css", File.DirDefaultExternal,"style.css")
           File.Copy(File.DirAssets,"script.js", File.DirDefaultExternal,"script.js")
       Else
'               dd
       End If
   End If
This are the results:
Logger connected to: samsung SM-J730F
--------- beginning of crash
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
is panel
drawing menu
is panel
drawing menu
drawing menu
drawing menu
drawing menu
drawing menu
wired: false
Speaker: false
false
DirAssets: AssetsDir
DirDefaultExternal: /storage/emulated/0/Android/data/com.lttech.md4x/files
DirRootExternal: /storage/emulated/0
DirInternal: /data/user/0/com.lttech.md4x/files
DirInternalCache: /data/user/0/com.lttech.md4x/cache
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
is panel
drawing menu
is panel
drawing menu
drawing menu
drawing menu
drawing menu
drawing menu
wired: false
Speaker: false
false
DirAssets: AssetsDir
DirDefaultExternal: /storage/emulated/0/Android/data/com.lttech.md4x/files
DirRootExternal: /storage/emulated/0
DirInternal: /data/user/0/com.lttech.md4x/files
DirInternalCache: /data/user/0/com.lttech.md4x/cache
Error occurred on line: 68 (Main)
java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.lttech.md4x/files/index.html (No such file or directory)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:308)
at java.io.FileOutputStream.<init>(FileOutputStream.java:238)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:448)
at anywheresoftware.b4a.objects.streams.File.Copy(File.java:341)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at com.lttech.md4x.main.afterFirstLayout(main.java:104)
at com.lttech.md4x.main.access$000(main.java:17)
at com.lttech.md4x.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7156)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)

I also do not understand where this text comes from: [com.lttech.md4x]
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Studying the answers given led to the insight that the elaboration of an HTML solution imposes limitations. The CSS layout and the JS should both be in-line. In practice, the layout with $ "" $ big string could run against the limit of approximately 64000 characters.

I take a new approach based on a local web server. This has the benefit of divided the logical program flow and presentation layer based on Erel's HTTP server example.
By changing:
B4X:
Sub Server_HandleRequest (Request As ServletRequest, Response As ServletResponse)
   Try
       Log("Client: " & Request.RemoteAddress & ", Request: " & Request.RequestURI)
in ServerService to
B4X:
Sub Server_HandleRequest (Request As ServletRequest, Response As ServletResponse)
   Try
       Log("Client: " & Request.RemoteAddress & ", Request: " & Request.RequestURI)
'       Limit respons to local users only
       Dim ssocket As ServerSocket
       If ssocket.GetMyWifiIP <> Request.RemoteAddress Then
           Log("Non-local user request dropped")
           Return
       End If
I Can limited the use to the local user only to protect the information.
Thank you very much guys, for guiding my.
 
Upvote 0
Top