mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-08 23:45:38 +02:00
36 lines
1.4 KiB
Java
36 lines
1.4 KiB
Java
package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
|
|
|
import android.bluetooth.BluetoothAdapter;
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.support.v4.content.LocalBroadcastManager;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
|
|
|
public class BluetoothStateChangeReceiver extends BroadcastReceiver {
|
|
@Override
|
|
public void onReceive(Context context, Intent intent) {
|
|
String action = intent.getAction();
|
|
|
|
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
|
|
if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_ON) {
|
|
|
|
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
|
|
LocalBroadcastManager.getInstance(context).sendBroadcast(refreshIntent);
|
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
if (!prefs.getBoolean("general_autoconnectonbluetooth", false)) {
|
|
return;
|
|
}
|
|
|
|
GBApplication.deviceService().connect();
|
|
} else if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_OFF) {
|
|
GBApplication.quit();
|
|
}
|
|
}
|
|
}
|
|
}
|