How to translate this to vb4pp

kalarius

Active Member
Licensed User
Longtime User
There is api in android for getting sd card serial id. The method is called getFatVolumeId(String mountPoint), where "mountPoint" is sd card name (you can get this name by calling Environment.getExternalStorageDirectory()). But getFatVolumeId is kindof hidden function (or forgotten), so you want to create package in your project named android.os and the class in it to reference the native method, to be able to call it:

package android.os;

public class FileUtils {
public static native int getFatVolumeId(String mountPoint);
}
And the code is:

File SdCard = Environment.getExternalStorageDirectory();
int Serial = FileUtils.getFatVolumeId(SdCard.getName());
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
   Dim r As Reflector
   Dim sdcard As Object, name As String
   sdcard = r.RunStaticMethod("android.os.Environment", "getExternalStorageDirectory", Null, Null)
   r.Target = sdcard
   name = r.RunMethod("getName")
   Log(r.RunStaticMethod("android.os.FileUtils", "getFatVolumeId", Array As Object(name), _
      Array As String("java.lang.String")))

It returns -1 here.
 
Upvote 0
Top