public class BluetoothMonitorReceiver extends BroadcastReceiver {
private static final String TAG = "BluetoothMonitorReceiver";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d(TAG,"action = " + action);
if(action != null){
switch (action) {
case BluetoothAdapter.ACTION_STATE_CHANGED:
int blueState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0);
switch (blueState) {
case BluetoothAdapter.STATE_TURNING_ON:
Log.d(TAG,"蓝牙正在打开");
break;
case BluetoothAdapter.STATE_ON:
Log.d(TAG,"蓝牙已经打开");
break;
case BluetoothAdapter.STATE_TURNING_OFF:
Log.d(TAG,"蓝牙正在关闭");
break;
case BluetoothAdapter.STATE_OFF:
Log.d(TAG,"蓝牙已经关闭");
break;
}
break;
case BluetoothDevice.ACTION_ACL_CONNECTED:
Log.d(TAG,"蓝牙设备已连接");
//.getInstance(context).updateBluetoothlist();
break;
case BluetoothDevice.ACTION_ACL_DISCONNECTED:
Log.d(TAG,"蓝牙设备已断开");
// CacheArrayManager.getInstance(HwContext.getContext()).disConnectGatt("val");
//CacheArrayManager.getInstance(context).updateBluetoothlist();
break;
case BluetoothDevice.ACTION_ALIAS_CHANGED:
Log.d(TAG,"蓝牙设备名称改变");
//CacheArrayManager.getInstance(context).updateBluetoothlist();
break;
}
}
}
}