Galaxy s6 Android LL: onConnectionStateChange вернуть мне 133 Статус ошибки

Я разработал приложение, которое должно переподключаться к серверному приложению, установленному на определенном устройстве. Я протестировал свое приложение на каком-то устройстве, но на galaxy s6 с Lollipop у меня возникли некоторые проблемы.

Это комбинация:

client (peripherall) is installed on galaxy tab 10.1 kitkat 
server (central role) is installed on galaxy s6 with lollipop 
ok

client (peripherall) is installed on galaxy nexus 6 lollipop
server (central role) is installed on galaxy s6 with lollipop 
ok

client (peripherall) is installed on galaxy s6 lollipop
server (central role) is installed on galaxy nexus 6 with lollipop 
not working

На последней комбинации функция соединения возвращает мне 133 статуса.

Это мой код:

public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    super.onConnectionStateChange(gatt, status, newState);
    Log.d("connect", "status = " + status + " newState = " + newState);
....

В чем разница между Киткат и Леденец? Нужно ли обрабатывать соединение по-другому?

public void new_automatization() {
    automatizationInProgress = true;
    Log.d("connect","new auto: si parte");
    this.init();
    Bluetooth.getMe().stopScan();
    final String MACaddress=getDataFromPreferences("address");
    final String keycode=getDataFromPreferences("unlockcode");  

    if(!Bluetooth.getMe().isScanning()) {
        Bluetooth.getMe().startScan(new Bluetooth.ScanCallback() {
            boolean deviceIsFound = false;

            @Override
            public void onDeviceFound(final BluetoothDevice device, int rssi,byte[] scanRecord) {
                Log.d("testAlpha","dentro onDeviceFound");
                if(device != null) {
                    String address=new String();                    
                    if(device.getName() != null) {  
                        Log.d("testAlpha","trovato name: "+device.getName()+"mac: "+device.getAddress());
                        address=device.getName();
                        if(address.equals(MACaddress)) {
                            Log.d("testAlpha","mi connetto a: "+device.getName()+"mac: "+device.getAddress());
                            Bluetooth.getMe().stopScan();//possiamo riconnetterci
                            deviceIsFound=true;
                            setDevice(device);
                            unlock(keycode);
                            automatizationInProgress = false;
                        }
                    }
                } else {
                    Log.i("connect","dentro onDeviceFound null");
                    search_ended=true;
                    sendMessage(DEVICE_NOT_FOUND);
                    automatizationInProgress = false;
                }   
            }
        });
    }
}

Это функция начального и конечного сканирования:

    @SuppressWarnings("deprecation")
    public boolean startScan(ScanCallback callback, final long timeout) {

        stopScan();         
        scanCallback = callback;
        /*
          if (isScanning()) {
            stopScan();
            return true;
          }
          scanCallback = callback;

        // Stops scanning after a pre-defined scan period (10s).
        stopTimer = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(timeout);
                } catch (InterruptedException e) {
                    Log.i("debug","interrupted");
                    return;
                }

                Log.i("debug","bluetooth: inizia lo stopscan()");

                if(!isScanning())
                    return;

                Log.i("debug","amgbluetooth: pre scansione");
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    BluetoothLeScanner scanner = bluetoothAdapter
                            .getBluetoothLeScanner();
                    scanner.stopScan(scanCallbackAfterLollipop);
                    scanning = false;
                } else {
                    bluetoothAdapter.stopLeScan(scanCallbackBeforeLollipop);
                    scanning = false;
                }
                Log.i("debug","amgbluetooth:stopTimer, invio null");

                if(!Thread.currentThread().isInterrupted())
                    scanCallback.onDeviceFound(null, 0, null);

            }
        });

        stopTimer.start();*/
        pippo.removeCallbacks(solPippo);
        pippo.postDelayed(solPippo, timeout);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            Log.i("finalT","amgbluetooth: inizia lo startscan() LL");

            BluetoothLeScanner scanner = bluetoothAdapter.getBluetoothLeScanner();
            scanning = true;

            scanCallbackAfterLollipop = new ScanCallback() {
                @Override
                public void onScanResult(int callbackType, ScanResult result) {
                    super.onScanResult(callbackType, result);
                    Log.d("finalT", "Single Result: "+result.getDevice().getName());

                    processResult(result);
                    /*
                    scanCallback.onDeviceFound(result.getDevice(), result.getRssi(), result.getScanRecord().getBytes());*/
                }

                @Override
                public void onBatchScanResults(List<ScanResult> results) {
                    Log.d("finalT", "onBatchScanResults: "+results.size()+" results");
                    /*
                      for (ScanResult result : results) {
                          processResult(result);
                      }*/
                  }

                  @Override
                  public void onScanFailed(int errorCode) {
                      Log.w("finalT", "LE Scan Failed: "+errorCode);
                  }

                  private void processResult(ScanResult result) {
                        BluetoothDevice device = result.getDevice();
                        Log.i("finalT", "New LE Device: " + device.getName() + " @ " + result.getRssi());

                        scanCallback.onDeviceFound(result.getDevice(),
                                result.getRssi(), result.getScanRecord()
                                        .getBytes());

                        //stopScan();
                    }
                };

                ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_BALANCED).setReportDelay(0).build();
                scanner.flushPendingScanResults(scanCallbackAfterLollipop);
                scanner.startScan(null,settings,scanCallbackAfterLollipop);
                return true;
            } else {
                Log.i("finalT","amgbluetooth: inizia lo startscan() < LL");
                scanning = true;
                scanCallbackBeforeLollipop = new LeScanCallback() {

                @Override
                public void onLeScan(BluetoothDevice device, int rssi,
                        byte[] scanRecord) {

                    Log.i("finalT","device trovato: "+device.getName());
                    scanCallback.onDeviceFound(device, rssi, scanRecord);
                }
            };


            return bluetoothAdapter.startLeScan(scanCallbackBeforeLollipop);
        }
    }

    public void stopScan() {
        Log.i("debug1","stopScan()");
        if(isScanning()) {
            Log.i("debug","stopScan() inside if");
            //stopTimer.interrupt();
            pippo.removeCallbacks(solPippo);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                BluetoothLeScanner scanner = bluetoothAdapter.getBluetoothLeScanner();
                scanner.stopScan(scanCallbackAfterLollipop);
                scanning = false;
            } else {
                bluetoothAdapter.stopLeScan(scanCallbackBeforeLollipop);
                scanning = false;
            }
        }
    }

и в unlock() Я называю функцию подключения.

PS: имя устройства, к которому я хочу подключиться (nexus 6), находится в переменной macaddress.

0 ответов

Другие вопросы по тегам