1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package safeluck.drive.evaluation.fragment;
 
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
 
import safeluck.drive.evaluation.app;
import safeluck.drive.evaluation.bean.AYBluetoothDevice;
 
/**
 * DriveJudge
 * Created by lzw on 2020/11/17. 13:51:16
 * 邮箱:632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class BluetoothManager {
    private static final BluetoothManager ourInstance = new BluetoothManager();
 
    private Context mContext;
 
    public static BluetoothManager getInstance() {
        return ourInstance;
    }
 
 
    AYBluetoothDevice ayBluetoothDevice;
    private BluetoothAdapter mBluetoothAdapter;
    private BluetoothManager() {
        this.mContext = app.getAppContext();
        android.bluetooth.BluetoothManager manager = (android.bluetooth.BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
        mBluetoothAdapter = manager.getAdapter();
    }
 
    public boolean isBluetoothEnable(){
        return mBluetoothAdapter.isEnabled();
    }
 
    public void startDiscovery(){
        if (mBluetoothAdapter.isDiscovering()){
            mBluetoothAdapter.cancelDiscovery();
        }
        mBluetoothAdapter.startDiscovery();
    }
 
    public void cancleDiscovery(){
        mBluetoothAdapter.cancelDiscovery();
    }
}