Fixed UnsatisfiedLinkError when initializing the HIDDeviceManager in some cases
authorSam Lantinga <slouken@libsdl.org>
Mon, 01 Oct 2018 14:52:28 -0700
changeset 12275be554ed7b4aa
parent 12274 736699aa224d
child 12276 9add34050395
Fixed UnsatisfiedLinkError when initializing the HIDDeviceManager in some cases
android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java	Mon Oct 01 14:43:03 2018 -0700
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java	Mon Oct 01 14:52:28 2018 -0700
     1.3 @@ -80,6 +80,14 @@
     1.4      public HIDDeviceManager(Context context) {
     1.5          mContext = context;
     1.6  
     1.7 +	// Make sure we have the HIDAPI library loaded with the native functions
     1.8 +        try {
     1.9 +            System.loadLibrary("hidapi");
    1.10 +        } catch (Exception e) {
    1.11 +            Log.w(TAG, "Couldn't load hidapi: " + e.toString());
    1.12 +            return;
    1.13 +        }
    1.14 +	
    1.15          HIDDeviceRegisterCallback(this);
    1.16  
    1.17          mSharedPreferences = mContext.getSharedPreferences("hidapi", Context.MODE_PRIVATE);
    1.18 @@ -180,7 +188,11 @@
    1.19      }
    1.20  
    1.21      protected void shutdownUSB() {
    1.22 -        mContext.unregisterReceiver(mUsbBroadcast);
    1.23 +        try {
    1.24 +            mContext.unregisterReceiver(mUsbBroadcast);
    1.25 +        } catch (Exception e) {
    1.26 +            // We may not have registered, that's okay
    1.27 +        }
    1.28      }
    1.29  
    1.30      protected boolean isHIDDeviceUSB(UsbDevice usbDevice) {