小编Inv*_*ame的帖子

Android lollipop java.lang.SecurityException:用户和当前进程都没有android.permission.BLUETOOTH_PRIVILEGED

我目前正在开发一个Android应用程序,它使用Eclipse(Java)通过蓝牙连接到设备.目前我在Android 4.4(Kit-Kat)及以下版本上工作,但在Android 5(Lollipop)的新更新之后.发生安全异常.

表现:

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
<uses-feature android:name="android.hardware.bluetooth_le"
        android:required="false" />
Run Code Online (Sandbox Code Playgroud)

码:

mBleScanner.startScan(filters, scanSettings, mLeScanCallback);

private ScanCallback mLeScanCallback = new ScanCallback()
{
    @Override
    public void onScanResult(int callbackType, ScanResult result)
    {
        BluetoothDevice device = result.getDevice();
        if(device.getName() != null)
        {
            if(device.getName().toUpperCase().contains("MyDevice"))
            {

                mBleScanner.stopScan(mLeScanCallback);

                if (device.getBondState() == BluetoothDevice.BOND_BONDED)
                {
                    Connect(device.getAddress().toString()); 
                }
                else
                {
                    // pair device
                    device.setPairingConfirmation(true);
                    device.createBond();
                }
            }
        }
    }
};
...
..
.
private void BondDevice(BluetoothGattCharacteristic bgc, boolean pnEnable)
{
    boolean bool = gatt.setCharacteristicNotification(bgc, …
Run Code Online (Sandbox Code Playgroud)

java android bluetooth-lowenergy android-bluetooth

8
推荐指数
1
解决办法
1807
查看次数