Android midi getDevices() not returning valid jobject

Hi JUCE Forum,

I have an application which opens midi ports to one or more class compliant midi devices which is functional on both macOS and iOS.

However, when I run the application on android, the MidiInput::getDevices() function returns an empty StringArray list, when I know for a fact that there is a midi device connected via usb (Android system debugging shows the UsbHostManager recognising the device).

When I stepped through the code, I reached the getDevices() function in juce_android_Midi.cpp, where the deviceManager.get() function does not return a valid object.

juce_android_Midi.cpp line 185 onwards :

    if (jobject dm = deviceManager.get()) //DOES NOT RETURN TRUE HERE
        jobjectArray jDevices
            = (jobjectArray) getEnv()->CallObjectMethod (dm, input ? MidiDeviceManager.getJuceAndroidMidiInputDevices
                                                              : MidiDeviceManager.getJuceAndroidMidiOutputDevices);
        // Create a local reference as converting this
        // to a JUCE string will call into JNI
        LocalRef<jobjectArray> devices (jDevices);
        return javaStringArrayToJuce (devices);

Am I missing something about detecting midi devices on Android, i.e. does anything extra have to be done apart from calling MidiInput::getDevices()?

Thanks in advance for the help, any thoughts are greatly appreciated

Hi @cSmout,

You need to be building for android marshmallow (23) or greater. MIDI is only supported since marshmallow.

You may also want to enable the bluetooth midi permissions if you are using midi over bluetooth.

Also, check out the MidiTest example in JUCE/examples/MIDITest