예제 #1
0
        public void Initialize()
        {
            this.argBuilder = new ArgJvalueBuilder();
            AndroidJNI.PushLocalFrame(32);
            var contxt = GetContext();

            this.bleManagerCls = GetGlobalRefClass("com/toio/ble/BleManagerObj");
            this.bleScannerCls = GetGlobalRefClass("com/toio/ble/BleScannerObj");
            this.bleDeviceCls  = GetGlobalRefClass("com/toio/ble/BleDeviceObj");
            var getInstanceMethod = AndroidJNI.GetStaticMethodID(bleManagerCls, "getInstance",
                                                                 "()Lcom/toio/ble/BleManagerObj;");

            var obj = AndroidJNI.CallStaticObjectMethod(bleManagerCls, getInstanceMethod, null);

            javaBleManagerObj = AndroidJNI.NewGlobalRef(obj);

            argBuilder.Clear().Append(ArgJvalueBuilder.GenerateJvalue(contxt.GetRawObject()));
            var initMethod = AndroidJNI.GetMethodID(bleManagerCls, "initialize", "(Landroid/content/Context;)V");

            AndroidJNI.CallVoidMethod(javaBleManagerObj, initMethod, argBuilder.Build());

            AndroidJNI.PopLocalFrame(IntPtr.Zero);
        }
예제 #2
0
        public void UpdateScannerResult()
        {
            AndroidJNI.PushLocalFrame(32);
            var scanner                   = GetScanner();
            var blitMethod                = AndroidJNI.GetMethodID(this.bleScannerCls, "blit", "()V");
            var getDeviceNumMethod        = AndroidJNI.GetMethodID(this.bleScannerCls, "getDeviceNum", "()I");
            var getDeviceAddrMethod       = AndroidJNI.GetMethodID(this.bleScannerCls, "getDeviceAddr", "(I)Ljava/lang/String;");
            var getDeviceNameByAddrMethod = AndroidJNI.GetMethodID(this.bleScannerCls, "getDeviceNameByAddr", "(Ljava/lang/String;)Ljava/lang/String;");
            var getRssiByAddrMethod       = AndroidJNI.GetMethodID(this.bleScannerCls, "getRssiByAddr", "(Ljava/lang/String;)I");

            AndroidJNI.CallVoidMethod(scanner, blitMethod, null);
            int num = AndroidJNI.CallIntMethod(scanner, getDeviceNumMethod, null);

            scannedDevices.Clear();
            for (int i = 0; i < num; ++i)
            {
                argBuilder.Clear().Append(ArgJvalueBuilder.GenerateJvalue(i));
                string addr = AndroidJNI.CallStringMethod(scanner, getDeviceAddrMethod, argBuilder.Build());
                argBuilder.Clear().Append(ArgJvalueBuilder.GenerateJvalue(addr));
                string name       = AndroidJNI.CallStringMethod(scanner, getDeviceNameByAddrMethod, argBuilder.Build());
                int    rssi       = AndroidJNI.CallIntMethod(scanner, getRssiByAddrMethod, argBuilder.Build());
                var    scanDevice = new BleScannedDevice(addr, name, rssi);
                this.scannedDevices.Add(scanDevice);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
        }