mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-27 20:36:51 +01:00
#15 automatically toggle the broadcast receiver using connectoin status
Makes "real" notifications where for the MI Band, not just those from the debug activity.
This commit is contained in:
parent
b74319fee9
commit
88e2b7ff99
@ -4,9 +4,11 @@ import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
@ -15,7 +17,6 @@ import android.preference.PreferenceManager;
|
||||
import android.provider.ContactsContract;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBDevice.State;
|
||||
import nodomain.freeyourgadget.gadgetbridge.miband.MiBandSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.pebble.PebbleIoThread;
|
||||
@ -56,9 +57,25 @@ public class BluetoothCommunicationService extends Service {
|
||||
private GBDevice mGBDevice = null;
|
||||
private DeviceSupport mDeviceSupport;
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(GBDevice.ACTION_DEVICE_CHANGED)) {
|
||||
String deviceAddress = intent.getStringExtra("device_address");
|
||||
GBDevice.State state = GBDevice.State.values()[intent.getIntExtra("device_state", 0)];
|
||||
if (mGBDevice.getAddress().equals(deviceAddress)) {
|
||||
mGBDevice.setState(state);
|
||||
GB.setReceiversEnableState(mGBDevice.isConnected(), context);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
registerReceiver(mReceiver, new IntentFilter(GBDevice.ACTION_DEVICE_CHANGED));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -195,6 +212,7 @@ public class BluetoothCommunicationService extends Service {
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
unregisterReceiver(mReceiver);
|
||||
GB.setReceiversEnableState(false, this); // disable BroadcastReceivers
|
||||
|
||||
if (mDeviceSupport != null) {
|
||||
|
@ -5,6 +5,9 @@ import android.content.Intent;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
|
||||
public class GBDevice {
|
||||
public static final String ACTION_DEVICE_CHANGED
|
||||
= "nodomain.freeyourgadget.gadgetbride.gbdevice.action.device_changed";
|
||||
|
||||
private final String name;
|
||||
private final String address;
|
||||
private final Type type;
|
||||
@ -75,7 +78,7 @@ public class GBDevice {
|
||||
|
||||
// TODO: this doesn't really belong here
|
||||
public void sendDeviceUpdateIntent(Context context) {
|
||||
Intent deviceUpdateIntent = new Intent(ControlCenter.ACTION_REFRESH_DEVICELIST);
|
||||
Intent deviceUpdateIntent = new Intent(ACTION_DEVICE_CHANGED);
|
||||
deviceUpdateIntent.putExtra("device_address", getAddress());
|
||||
deviceUpdateIntent.putExtra("device_state", getState().ordinal());
|
||||
deviceUpdateIntent.putExtra("firmware_version", getFirmwareVersion());
|
||||
|
Loading…
Reference in New Issue
Block a user