Before 1.+ in Android SDK (0.16.0) in the class Utils there was a function restartBluetooth.
In 1.+ I can’t find it.
Is this function still there?
Before 1.+ in Android SDK (0.16.0) in the class Utils there was a function restartBluetooth.
In 1.+ I can’t find it.
Is this function still there?
Utils class was removed. See https://github.com/Estimote/Android-SDK/issues/247
Restarting Bluetooth is pretty straightforward. Here is a code snippet (from old SDK) that allows to do this.
/**
* Restarts Bluetooth stack on the device.
* <p>
* <b>Never</b> invoke this method without user's explicit consent that Bluetooth
* on the device is going to be restarted.
*
* @param context Context.
* @param listener Listener to be invoked when Bluetooth stack is restarted.
*/
public static void restartBluetooth(Context context, final RestartCompletedListener listener) {
BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
final BluetoothAdapter adapter = bluetoothManager.getAdapter();
IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
context.registerReceiver(new BroadcastReceiver() {
@Override public void onReceive(Context context, Intent intent) {
if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) {
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1);
if (state == BluetoothAdapter.STATE_OFF) {
adapter.enable();
} else if (state == BluetoothAdapter.STATE_ON) {
context.unregisterReceiver(this);
listener.onRestartCompleted();
}
}
}
}, intentFilter);
adapter.disable();
}
Remember that restarting Bluetooth without user’s explicit approval is a very bad idea - you basically restart whole stack, so you may break connection with other Bluetooth devices like headphones or speakers.