Android Question File.DirAssets full path

wonder

Expert
Licensed User
Longtime User
Hello B4A guru's,

Is there a way, in B4A (JavaObject, Reflection, Inline Java, etc...), to obtain the File.DirAssets full path?
 

wonder

Expert
Licensed User
Longtime User
It's a bitmap file. The function works perfectly, I was only wondering if I could load files directly from DirAssets.

B4A:
B4X:
Dim ms As MazeSolver

'This doesn't work, my function returns FALSE
ms.MazeMatrixLoadBMP(File.DirAssets & "/yeah.bmp")

'...but if I copy the file to DefaultExternal it works (returns TRUE)
ms.MazeMatrixLoadBMP(File.DirDefaultExternal & "/yeah.bmp")

Java:
B4X:
...
...
public native boolean MazeMatrixLoadBMP(long matrixAddress, String strFilename);
...
...

C++ (JNI):
B4X:
JNIEXPORT jboolean JNICALL Java_com_ninjadynamics_mazesolver_MazeSolver2_MazeMatrixLoadBMP(JNIEnv *env, jobject jobj, jlong matrixAddress, jstring strFilename)
{
    const char* filename;
    filename = env->GetStringUTFChars(strFilename, NULL);

    Matrix *workingMatrix = (Matrix*)(matrixAddress);

    FILE* f = fopen(filename, "rb");
    if (f == NULL)
        return false;
    ...
    ...
    ...
    ...
    return true;
}
 
Last edited:
Upvote 0

Informatix

Expert
Licensed User
Longtime User
It's a bitmap file. The function works perfectly, I was only wondering if I could load files directly from DirAssets.

B4A:
B4X:
Dim ms As MazeSolver

'This doesn't work, my function returns FALSE
ms.MazeMatrixLoadBMP(File.DirAssets & "/yeah.bmp")

'...but if I copy the file to DefaultExternal it works (returns TRUE)
ms.MazeMatrixLoadBMP(File.DirDefaultExternal & "/yeah.bmp")

Java:
B4X:
...
...
public native boolean MazeMatrixLoadBMP(long matrixAddress, String strFilename);
...
...

C++ (JNI):
B4X:
JNIEXPORT jboolean JNICALL Java_com_ninjadynamics_mazesolver_MazeSolver2_MazeMatrixLoadBMP(JNIEnv *env, jobject jobj, jlong matrixAddress, jstring strFilename)
{
    const char* filename;
    filename = env->GetStringUTFChars(strFilename, NULL);

    Matrix *workingMatrix = (Matrix*)(matrixAddress);

    FILE* f = fopen(filename, "rb");
    if (f == NULL)
        return false;
    ...
    ...
    ...
    ...
    return true;
}
You'll find an example of access to these files in Java in the source code of FastIO (in the ProBundle, function ReadArrayFromAssets).
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
From Java you can call anywheresoftware.b4a.objects.streams.File.OpenInput(anywheresoftware.b4a.objects.streams.File.getDirAssets, "file name"))

This is the best way as it will correctly handle the differences between debug and release modes.

However there is another option, which is to let the developer who is using the library to pass an InputStream to the method.
 
Upvote 0
Top