【问题标题】:Permission Denial: not allowed to send broadcast android.bluetooth.device.action.FOUND权限拒绝:不允许发送广播 android.bluetooth.device.action.FOUND
【发布时间】:2015-12-28 20:11:49
【问题描述】:

我正在尝试发送广播。执行后出现如下错误:

java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.bluetooth.device.action.FOUND from pid=24885, 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"/>

【问题讨论】:

  • 你为什么要发送这个动作?它是由系统发送的。为什么要覆盖在onReceive() 中收到的intent?看起来很破的代码。
  • 我是 android 编码的新手。因此,我不太了解流程。你知道我如何获得发现的蓝牙设备列表吗?

标签: android bluetooth permissions android-broadcast


【解决方案1】:

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

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

【讨论】:

  • 使用相同的权限或其他问题?
  • 我用另一种方式解决了问题。我没有发送广播,而是注册了我的接收器。这就是全部了。我一回到家就分享新方法。 :)
猜你喜欢
  • 2014-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-13
  • 1970-01-01
  • 2017-06-11
  • 2011-04-18
  • 2019-10-24
相关资源
最近更新 更多