BluetoothConnectActivityReceiver.java
1.24 KB
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
48
49
package com.eztlib.blu;
import com.ectrip.cyt.config.MyApp;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class BluetoothConnectActivityReceiver extends BroadcastReceiver {
String strPsw = "1234";
@Override
public void onReceive(Context context, final Intent intent) {
try {
if (intent.getAction().equals(
"android.bluetooth.device.action.PAIRING_REQUEST")) {
if (MyApp.getInstance().isHandset) {
new Thread() {
@Override
public void run() {
BluetoothDevice btDevice = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// byte[] pinBytes =
// BluetoothDevice.convertPinToBytes("1234");
// device.setPin(pinBytes);
try {
ClsUtils.setPin(btDevice.getClass(), btDevice,
strPsw); // 手机和蓝牙采集器配对
ClsUtils.createBond(btDevice.getClass(),
btDevice);
ClsUtils.cancelPairingUserInput(
btDevice.getClass(), btDevice);
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}