NOT able to turn off the bluetooth when android api level is 33 and Android OS is 13 but the same code is working on andorid 13 with API 31
public void toggleBluetooth(boolean enable) { try{ if (enable && !bluetoothAdapter.isEnabled()) { final int BLUETOOTH_REQUEST_CODE = 1;
if (ContextCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_ADMIN)
!= PackageManager.PERMISSION_GRANTED) {
Log.e("AUTOTEST_BLUETOOTH","DENIED");
ActivityCompat.requestPermissions(activity,
new String[]{Manifest.permission.BLUETOOTH_ADMIN}, BLUETOOTH_REQUEST_CODE);
}
if (ContextCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH)
!= PackageManager.PERMISSION_GRANTED) {
Log.e("AUTOTEST_BLUETOOTH","DENIED");`your text`
ActivityCompat.requestPermissions(activity,
new String[]{Manifest.permission.BLUETOOTH}, BLUETOOTH_REQUEST_CODE);
}
bluetoothAdapter.enable();
} else if (!enable && bluetoothAdapter.isEnabled()) {
Log.e("AUTOTEST_BLUETOOTH","DISABLED");
bluetoothAdapter.disable();
}
}
catch (Exception e)
{
Log.e("BLUETOOTH_EXCEPTION",e.getMessage());
}
}