Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Android: Access / open USB devices (Java Activity instead of native Activity?)  (Read 3787 times)

0 Members and 1 Guest are viewing this topic.

jwurzer

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Hi!

I use SFML for Android. Now I want to access a USB device (MIDI device adapter for my piano). Currently I access the USB Manager from my C++ Code per JNI with GetMethodID, CallObjectMethod, ... etc. That's all no problem. The problem starts with opening the USB device. I insert <uses-feature android:name="android.hardware.usb.host" /> to my manifest file but I have no idea to make the necessary requestPermission() call from JNI to granted the access for opening the device with openDevice from USB manager. If I have a valid file descriptor from the opened usb device then the access per NDK should be no problem using ioctl and bulk transfer (see: http://stackoverflow.com/questions/16963237/passing-usb-file-descriptor-to-android-ndk-program ). For SFML I think the problem could be interresting for the SFML project because SFML maybe want to support joysticks which are connected per USB.

My current solution would be to use a normal/java activity instead of a native activity with SFML and write the necessary code in java to open the usb device and transfer the opened file descriptor to my native code.

Now I have two questions ;-)
1) Is there a possible solution without Java code?
2) Is there a example of using SFML with a activity (java) instead of using SFML with a native activity?

Sorry for my bad english :-)

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Never tried it before, but you should be able to just add your Java snippet as extra code (as you'd do for a non-native activity) and then call that Java code using the JNI?

 

anything