Android Question DJI Mediamanager

javiman6969

Member
Licensed User
Longtime User
Hello friends!
Could someone give me an example of how to use MediaManager from the Camera class of the DJI SDK?

I can't access the content of the drone's SD.

I use:

B4X:
    Dim mediamanager As JavaObject = camera
       
    mediamanager = mediamanager.RunMethod("getMediaManager", Null)
       
    Dim callback As Object = mediamanager.CreateEventFromUI("dji.common.MediaManager$MediaManagerCallback", "MediaManager", Null)
    mediamanager.RunMethod("getScheduler",Array(callback))

java.lang.RuntimeException: Method: getMediaManager not found in: anywheresoftware.b4a.objects.DJICameraWrapper
 
Last edited:

javiman6969

Member
Licensed User
Longtime User
Thanks Erel.
The result is: java.lang.RuntimeException: Object should first be initialized (JavaObject).

I have no experience in using Java, nor in how to make use of the DJI SDK using direct calls to Java.

Can you give me an example where it can be seen clearly how to do this?


B4X:
    Dim mediamanager As JavaObject = camera
    
    mediamanager.InitializeStatic("dji.sdk.camera")
    mediamanager = mediamanager.GetFieldJO("camera").RunMethod("getMediaManager", Null)


Result ERROR:

java.lang.ClassNotFoundException: dji$sdk$camera
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:309)
at java.lang.Class.forName(Class.java:273)
at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:274)
at anywheresoftware.b4j.object.JavaObject.InitializeStatic(JavaObject.java:75)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
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 java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:4809)
at android.view.View$PerformClick.run(View.java:20006)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5282)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:966)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
Caused by: java.lang.ClassNotFoundException: Didn't find class "dji$sdk$camera" on path: DexPathList[[zip file "/data/data/com.dji.aerodefectscan/.cache_sdk/sdkclasses2.jar", zip file "/data/data/com.dji.aerodefectscan/.cache_sdk/sdkclasses.jar", zip file "/system/framework/com.android.future.usb.accessory.jar", zip file "/data/app/com.dji.aerodefectscan-2/base.apk"],nativeLibraryDirectories=[/data/app/com.dji.aerodefectscan-2/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
... 26 more
Suppressed: java.lang.ClassNotFoundException: dji$sdk$camera
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 27 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available




Thanks!
 
Last edited:
Upvote 0

javiman6969

Member
Licensed User
Longtime User
The code:

B4X:
    Dim mediamanager As JavaObject = camera
    mediamanager = mediamanager.GetFieldJO("camera").RunMethod("getMediaManager", Null)

report de error:
java.lang.RuntimeException: Object should first be initialized (JavaObject).

I tried to fix it with the code:
B4X:
    Dim mediamanager As JavaObject = camera
        
    mediamanager.InitializeStatic("dji.sdk.camera")
    mediamanager = mediamanager.GetFieldJO("camera").RunMethod("getMediaManager", Null)


And the error is:

java.lang.ClassNotFoundException: com$dji$camera
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
java.lang.RuntimeException: Object should first be initialized (JavaObject).
This means that the camera isn't ready yet.

You can change it to:
B4X:
Dim ncamera As JavaObject = camera
ncamera = ncamera .GetField("camera")
If nCamera.IsInitialized Then
    mediamanager = nCamera.RunMethod("getMediaManager", Null)
End If
 
Upvote 0

javiman6969

Member
Licensed User
Longtime User
Ok. Thanks!!!!!
I need to be able to access the SD of the DRON using the MediaManagery class to download the images.

How can I create a download event and launch the download method?
I have very little knowledge of JAVA.

Thanks.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…