所以我的设备是静音设备。我想要的是,当我从其他设备向khadas发送配对请求时,设备会自动配对。问题是,当发送蓝牙配对请求时,会出现带有PIN的配对确认提示。我已经设置了广播接收器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中添加了该权限,并且也将该应用程序安装为系统应用程序,但仍然无法正常工作。
答案 0 :(得分:0)
找到了解决方案,如果您具有root用户访问权限,并且要将该应用程序安装为系统应用程序以获取bluetooth_privileged权限。将apk复制到/ system / priv-app而不是/ system / app