Bluetooth ACTION_FOUND broadcastReceiver is not working
I finally found answer. Android 6.0 needs additional permission, but Just adding uses-permission to Manifest is not working. You have to check permission to user. I write my code like this:
int permissionCheck = ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.ACCESS_COARSE_LOCATION);
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (!bluetoothAdapter.isEnabled())
bluetoothAdapter.enable();
leScanner = bluetoothAdapter.getBluetoothLeScanner();
Button boton = (Button) findViewById(R.id.button1);
boton.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
leScanner.startScan(scanCallback);
}
});
This code show you permission pop up. Thanks for many answers.
You need a force request of ACCESS_COARSE_LOCATION
permission:
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_CODE);
}
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
...
Found at https://www.sitepoint.com/requesting-runtime-permissions-in-android-m-and-n