[英]Android Bluetooth pairing Security
自从我升级到android 4.2后,当我尝试配对设备时我遇到了问题设备应该配对但现在它说需要across_user_permission。
这是错误日志:
错误:代码3:
java.lang.SecurityException异常::
权限拒绝:来自android的广播请求以用户-1运行但是从user0调用; 这需要
android.permission.INTERACT_ACROSS_USERS_FULL或
android.permission.INTERACT_ACROSS_USERS。
在这里我的方法:
public boolean ensurePaired(BluetoothDevice bd) {
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(bd.getAddress());
boolean paired = false;
Log.d(TAG,"Pairing with Bluetooth device with name " + device.getName()+" and address "+device.getAddress());
try {
Method m = device.getClass().getMethod("createBond");
paired = (Boolean) m.invoke(device);
} catch (Exception e)
{
return paired;
}
Log.d("BluetoothPlugin -", "Returning "+ "Result: "+paired);
return paired;
}
我会将代码更改为:
public boolean ensurePaired(BluetoothDevice bd) {
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(bd.getAddress());
Log.d(TAG,"Pairing with Bluetooth device with name " + device.getName()+" and address "+device.getAddress());
if(device.getBondState() != BluetoothDevice.BOND_BONDED){
device.createBond();
}
}
createBond是一个异步调用,它会立即返回。 注册ACTION_BOND_STATE_CHANGED意图,以便在绑定过程完成时得到通知及其结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.