安卓蓝牙配对安全性

6
自从我升级到Android 4.2后,当我尝试配对设备时遇到了麻烦。该设备应该已经配对,但现在它显示需要 across_user_permission 权限。
以下是错误日志:
error:code 3: java.lang.SecurityException:: Permission Denial: broadcast from android asks to run as user -1 but is calling from user0; this requires android.permission.INTERACT_ACROSS_USERS_FULL or 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;
}
1个回答

1
我会将代码更改为:

我会将代码更改为:

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意图以在绑定过程完成及其结果时接收通知。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接