1

I am not able to get my ble scanner working.There is no scanCalll Back is occuring.

Below is my code: MainActivity:

public class MainActivity extends AppCompatActivity  {

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        BluetoothUtil b = new BluetoothUtil();
        b.startScan();

    }


}

}

BluetoothUtil:

public class BluetoothUtil extends ScanCallback {

BluetoothAdapter badap = BluetoothAdapter.getDefaultAdapter();
ScanSettings.Builder builder = new ScanSettings.Builder();


public BluetoothUtil() {

    super();
    builder.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY);
}

@Override
public void onScanResult(int callbackType, ScanResult result) {
    Log.v("test","Scanning Occurred");
    super.onScanResult(callbackType, result);
}

public void startScan() {
 if(badap !=null)
{
    ScanSettings.Builder builder = new ScanSettings.Builder();
    builder.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY);
    if (BluetoothAdapter.getDefaultAdapter().getState() == BluetoothAdapter.STATE_ON) {
        BluetoothAdapter.getDefaultAdapter().getBluetoothLeScanner().startScan(new ArrayList<ScanFilter>(), builder.build(), this);
//            
BluetoothAdapter.getDefaultAdapter().getBluetoothLeScanner().startScan(this);
    }
}
}
}
Raulp
  • 7,758
  • 20
  • 93
  • 155

1 Answers1

0

My fault. Post android 6 you have to set the permissions for the app from the app gui permissions. You have to enable location and bluetooth . Worked now !

Raulp
  • 7,758
  • 20
  • 93
  • 155