【发布时间】:2018-08-10 07:11:47
【问题描述】:
所以我的设备是静音设备。我想要的是,当我从不同的设备向 khadas 发送配对请求时,设备会自动配对。问题是当发送蓝牙配对请求时,会出现带有密码的配对确认提示。我已经设置了一个广播接收器from here,但似乎没有任何工作代码是:
private final BroadcastReceiver mPairingRequestReceiver = new BroadcastReceiver()
{
public void onReceive(Context context, Intent intent)
{
Log.v("BDE", "recieved something!");
String action = intent.getAction();
if (action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST))
{
try
{
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
int pin = intent.getIntExtra("android.bluetooth.device.extra.PAIRING_KEY", 1234);
//the pin in case you need to accept for an specific pin
Log.d(TAG, "Start Auto Pairing. PIN = " + intent.getIntExtra("android.bluetooth.device.extra.PAIRING_KEY", 1234));
byte[] pinBytes;
pinBytes = ("" + pin).getBytes("UTF-8");
device.setPin(pinBytes);
//setPairing confirmation if needed
device.setPairingConfirmation(true);
} catch (Exception e)
{
e.printStackTrace();
Log.e(TAG, "Error occurs when trying to auto pair");
e.printStackTrace();
}
}
}
};
当我运行此代码时,我收到错误“原因:java.lang.SecurityException:需要 BLUETOOTH PRIVILEGED 权限:用户 10068 和当前进程都没有 android.permission.BLUETOOTH_PRIVILEGED。”
我在 Android Manifest 中也添加了权限,并将应用程序安装为系统应用程序,但仍然无法使用。
【问题讨论】: