瀏覽代碼

Fixed UnsatisfiedLinkError when initializing the HIDDeviceManager in some cases

Sam Lantinga 7 年之前
父節點
當前提交
679d355317
共有 1 個文件被更改,包括 13 次插入1 次删除
  1. 13 1
      android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java

+ 13 - 1
android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java

@@ -80,6 +80,14 @@ public class HIDDeviceManager {
     public HIDDeviceManager(Context context) {
         mContext = context;
 
+	// Make sure we have the HIDAPI library loaded with the native functions
+        try {
+            System.loadLibrary("hidapi");
+        } catch (Exception e) {
+            Log.w(TAG, "Couldn't load hidapi: " + e.toString());
+            return;
+        }
+	
         HIDDeviceRegisterCallback(this);
 
         mSharedPreferences = mContext.getSharedPreferences("hidapi", Context.MODE_PRIVATE);
@@ -180,7 +188,11 @@ public class HIDDeviceManager {
     }
 
     protected void shutdownUSB() {
-        mContext.unregisterReceiver(mUsbBroadcast);
+        try {
+            mContext.unregisterReceiver(mUsbBroadcast);
+        } catch (Exception e) {
+            // We may not have registered, that's okay
+        }
     }
 
     protected boolean isHIDDeviceUSB(UsbDevice usbDevice) {