package com.example.blu.toys.ble.receiver;

import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.blankj.utilcode.util.LogUtils;
import com.clj.fastble.BleManager;
import com.clj.fastble.callback.BleScanCallback;
import com.clj.fastble.data.BleDevice;

import java.util.List;


/**
 * 作者: 程冲
 * 时间: 2018/3/26.
 */

public class BluetoothOpenAndClose extends BroadcastReceiver {

	@Override
	public void onReceive(final Context context, Intent intent) {

		String action = intent.getAction();
		if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
			int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
					BluetoothAdapter.ERROR);
			switch (state) {
				case BluetoothAdapter.STATE_OFF:
					LogUtils.e("蓝牙断开");
					break;
				case BluetoothAdapter.STATE_TURNING_OFF:
					LogUtils.d("手机蓝牙正在关闭");
					break;
				case BluetoothAdapter.STATE_ON:
					LogUtils.d("手机蓝牙开启");
//
//					BleScanRuleConfig scanRuleConfig = new BleScanRuleConfig.Builder()
//							.setServiceUuids(serviceUuids)
//							//.setDeviceName(true, names)
//							//.setDeviceMac(mac)
//							.setAutoConnect(false)
//							.setScanTimeOut(10000)
//							.build();
					//BleManager.getInstance().initScanRule(scanRuleConfig);






					break;
				case BluetoothAdapter.STATE_TURNING_ON:
					LogUtils.d("STATE_TURNING_ON 手机蓝牙正在开启");
					break;
			}
		}
	}
}
