title: Android BluetoothDevice createBond permissions error
body: <p>I have a project with both</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.BLUETOOTH"/&gt;
  &lt;uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/&gt;
  </code></pre>
  
  <p>In it I make a call to scan for BT devices using (simplified):</p>
  
  <pre><code>final BluetoothLeScanner scanner = BluetoothAdapter.getDefaultAdapter()
          .getBluetoothLeScanner()
  ArrayList&lt;ScanFilter&gt; scanFilters = ArrayList&lt;&gt;();
  scanFilters.add(new ScanFilter.Builder()
          .setServiceUuid(new ParcelUuid(MY_SERVICE_UUID))
          .build());
  ScanSettings scanSettings = new ScanSettings.Builder()
          .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
          .build();
  ScanCallback scanCallback = new ScanCallback() {
      @Override
      void onScanFailed(int errorCode) {}
      @Override
      void onScanResult(int callbackType, ScanResult result) {
          result.getDevice().createBond();
          scanner.stopScan(this);
      }
      @Override
      public void onBatchScanResults(List&lt;ScanResult&gt; results) {}
  };
  scanner.startScan(scanFilters, scanSettings, scanCallback);
  </code></pre>
  
  <p>The gist is that I scan for a device with my service, and for now just bond to the first one I see. All my characteristics and descriptors are using read/write_encrypted permissions (I don't know if that matters). What I end up seeing is the pairing screens on both devices but later when I use the <code>connectGatt</code> method I fail with the following error:</p>
  
  <pre><code>E/bt_btif: bta_gattc_cache_load: can't open GATT cache file /data/misc/bluetooth/gatt_cache_76fe0b7bf8dd for reading, error: No such file or directory
  E/bt_att: gatt_disc_cmpl_cback() - Unable to register for service changed indication
  </code></pre>
  
  <p>If, on the other hand, I open the BT settings and bond the devices from there, everything works great! <code>connectGatt</code> works and I can read/write data as I please.</p>
  
  <p>What am I doing wrong with <code>createBond()</code>?</p>