【发布时间】: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