权限拒绝:不允许发送广播android.bluetooth.device.action.FOUND

时间:2015-12-28 20:11:50

标签: android bluetooth permissions android-broadcast

我正在尝试发送广播。执行后,我收到以下错误:

java.lang.SecurityException:Permission Denial:不允许从pid = 24885发送广播android.bluetooth.device.action.FOUND,uid = 10370

如果有人遇到此错误,我们将非常感谢您的帮助。这是我的方法:

    private void DiscoverOBDConnection() {
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBluetoothAdapter.startDiscovery();

// Create a BroadcastReceiver for ACTION_FOUND
final List<String> discoverableDevicesList = new ArrayList<String>();
final BroadcastReceiver mReceiver = new BroadcastReceiver() {
  public void onReceive(Context context, Intent intent) {
    intent=new Intent(BluetoothDevice.ACTION_FOUND);
    String action = intent.getAction();
    // When discovery finds a device
    sendBroadcast(intent);
    if (BluetoothDevice.ACTION_FOUND.equals(action)) {
      // Get the BluetoothDevice object from the Intent
      BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
      discoverableDevicesList.add(device.getName() + "\n" + device.getAddress() + "\n");
      String discoveredDeviceName = device.getName();
      }
    }
  }
};
mReceiver.onReceive(this, new Intent(BluetoothDevice.ACTION_FOUND));

}

清单权限:

  <uses-permission android:name="android.permission.BLUETOOTH"/>

  

1 个答案:

答案 0 :(得分:0)

添加管理员权限以访问蓝牙

    <uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />