Android Question How to get that? (Device info about sd card and USB stick)

rosippc64a

Active Member
Licensed User
Longtime User
Hi All!
I can sense device (SD card and USB stick) attaching and removing with example found here.
B4X:
Sub Service_Start (StartingIntent As Intent)
    If(StartingIntent.Action = "android.intent.action.MEDIA_MOUNTED") Or _
        (StartingIntent.Action = "android.intent.action.MEDIA_REMOVED") Then
        Dim JO As JavaObject = StartingIntent
        Dim ud As UsbDevice = JO.RunMethod("getParcelableExtra",Array As Object("android.os.storage.extra.STORAGE_VOLUME"))
...
When I place cursor above the "ud", then I can see debug info. There appears two item:
mDescription and mFsUuid. They are the volume label and the volume ID what I need very much. (maybe there is a third: mPath -> path)
How can I get them?
thanks in advance
Steven
deviceinfo.png


I can see, that these datas are in startingintent also, but the question remains: ho to get them?

Yes, maybe with javaobject, but If I try field name as mDescription of Description, then there is an error.
B4X:
Dim JO1 As JavaObject = ud
Log(JO1.GetField("Description"))
 
Last edited:

rosippc64a

Active Member
Licensed User
Longtime User
I don't know how to do it. I didn't use intents before, but if I try that:
Log(StartingIntent.ExtrasToString)
then I get:
Bundle[{android.os.storage.extra.STORAGE_VOLUME=StorageVolume: KINGSTON (424610224610196D)}]
Of course I see the searched data is there, but I am interested in a native solution if any, not a text processing method. :)
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
Thank you Erel, that works. But what is the description?
The Log(StorageVolume.RunMethod("getDescription", Null)) make an exception.
How will be StorageVolume.RunMethod("getUuid", Null) from an mFsUuid and why not works the
StorageVolume.RunMethod("getDescription", Null)?
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
Thank you for the reply, but now I can see, I don't know the inner world of the java. Now I have next question, how to get the right context?
I tried a lot of, i.e.:
Dim cls As String = Main.Mainme 'this part runs in a service, the main.mainme is the main activity Me, but local Me is also wrong
cls = cls.SubString("class ".Length)
Dim joc As JavaObject
'joc.InitializeStatic(cls)
joc.InitializeNewInstance (cls, Null)
Dim context As JavaObject = Main.MainMe 'joc.GetFieldJO("processBA")
Log(StorageVolume.RunMethod("getDescription", Array As Object(context)))
but neither good: all resulted an "java.lang.RuntimeException: Method: getDescription not matched.". I see, that neither of my context right as param of getDescription.
 
Last edited:
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
There was no relevant code but a lot of unsuccessful trying.

B4X:
Dim cls As String = Main.Mainme 'this part runs in a service, the main.mainme is the main activity Me, but local Me is also wrong
cls = cls.SubString("class ".Length)
Dim joc As JavaObject
'joc.InitializeStatic(cls)
joc.InitializeNewInstance (cls, Null)
Dim context As JavaObject = Main.MainMe 'joc.GetFieldJO("processBA")
Log(StorageVolume.RunMethod("getDescription", Array As Object(context)))
 
Upvote 0
Top