我最近在华为Mate 9设备上安装了Android 9.0。 在安装Android 8之前,BluetoothDevice.setPin一直运行良好。 有什么线索为什么这不再起作用了?
public class BlututReceiver extends BroadcastReceiver {
private final static byte[] PIN = "0000".getBytes();
public void onReceive(android.content.Context r7, android.content.Intent intent) {
BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String action = intent.getAction();
if (BluetoothDevice.ACTION_PAIRING_REQUEST.equals(action)) {
sendPin(bluetoothDevice);
}
}
private void sendPin(BluetoothDevice bluetoothDevice) {
try {
Thread.sleep(100);
bluetoothDevice.setPin(PIN);
bluetoothDevice.createBond();
//bluetoothDevice.setPairingConfirmation(true);
//bluetoothDevice.getClass().getMethod("setPairingConfirmation", new Class[]{Boolean.TYPE}).invoke(bluetoothDevice, new Object[]{Boolean.valueOf(true)});
} catch (Exception e) {
Log.e("BLUETOOTHSETPINERR",e.getMessage());
}
}
}
<receiver android:name=".Utile.BlututReceiver">
<intent-filter android:priority="1000">
<action android:name="android.bluetooth.device.action.PAIRING_REQUEST" />
</intent-filter>
</receiver>
答案 0 :(得分:0)
它在带有Android Pie的Xiaomi Mi 9中正常工作。看来这是华为的问题。我尝试使用HUAWEI P10和HUAWEI PSMART(两者都使用Android Pie),但无法正常工作。