2015-04-27 12 views
7

Aktualnie pracuję nad aplikacją na Androida, która łączy się z urządzeniem przez Bluetooth za pomocą Eclipse (Java). Obecnie mam go działa na Android 4.4 (Kit-Kat) i poniżej, ale po nowej aktualizacji, która jest Android 5 (Lolipop). Wystąpił wyjątek zabezpieczeń.android lolipop java.lang.SecurityException: Ani użytkownik, ani obecny proces nie ma android.permission.BLUETOOTH_PRIVILEGED

Oczywisty:

<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" /> 

Kod:

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, true); // this line throw security exception 
    BluetoothGattDescriptor bgd=bgc.getDescriptor(UUID.fromString(BLE_DESCRIPTOR_NOTIFY)); 

    byte[] arrayOfByte = pnEnable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE: 
         BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE; 
    gattDescriptor.setValue(arrayOfByte); 
    mBluetoothGatt.writeDescriptor(bgd); 
} 

stosu Ślad:

04-27 12:36:24.559: W/BluetoothGatt(17764): Unhandled exception in callback 
04-27 12:36:24.559: W/BluetoothGatt(17764): java.lang.SecurityException: Need BLUETOOTH_PRIVILEGED permission: Neither user 10215 nor current process has android.permission.BLUETOOTH_PRIVILEGED. 
04-27 12:36:24.559: W/BluetoothGatt(17764):  at android.os.Parcel.readException(Parcel.java:1540) 
04-27 12:36:24.559: W/BluetoothGatt(17764):  at android.os.Parcel.readException(Parcel.java:1493) 
04-27 12:36:24.559: W/BluetoothGatt(17764):  at android.bluetooth.IBluetoothGatt$Stub$Proxy.registerForNotification(IBluetoothGatt.java:1163) 
04-27 12:36:24.559: W/BluetoothGatt(17764):  at android.bluetooth.BluetoothGatt.setCharacteristicNotification(BluetoothGatt.java:1239) 
04-27 12:36:24.559: W/BluetoothGatt(17764):  at com.vibease.ap3.service.ServiceBLE.BondDevice(ServiceBLE.java:568) 
04-27 12:36:24.559: W/BluetoothGatt(17764):  at com.vibease.ap3.service.ServiceBLE.CheckDevice(ServiceBLE.java:518) 
04-27 12:36:24.559: W/BluetoothGatt(17764):  at com.vibease.ap3.service.ServiceBLE.access$7(ServiceBLE.java:493) 
04-27 12:36:24.559: W/BluetoothGatt(17764):  at com.vibease.ap3.service.ServiceBLE$2.onServicesDiscovered(ServiceBLE.java:373) 
04-27 12:36:24.559: W/BluetoothGatt(17764):  at android.bluetooth.BluetoothGatt$1.onSearchComplete(BluetoothGatt.java:309) 
04-27 12:36:24.559: W/BluetoothGatt(17764):  at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:217) 
04-27 12:36:24.559: W/BluetoothGatt(17764):  at android.os.Binder.execTransact(Binder.java:446) 

Wszelkie porady? Dziękuję Ci.

+0

try sowmia

+0

Problem nadal istnieje –

Odpowiedz

0

Wygląda na to, że Google zmienia trochę zabezpieczenia w układzie Bluetooth. Mój układ Bluetooth zawiera część adresu, który został zablokowany przez to zabezpieczenie. Dlatego napotkałem mój problem. Ponieważ użyłem innego chipa. Teraz wszystko działa dobrze.

P/s: zapomniałem odpowiedzieć na to dawno temu

1

04-27 12:36:24.559: W/BluetoothGatt(17764): java.lang.SecurityException: Need BLUETOOTH_PRIVILEGED permission: Neither user 10215 nor current process has android.permission.BLUETOOTH_PRIVILEGED .

Wystarczy dodać uprawnienie to z prośbą o:

<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" /> 
+0

Dziękuję za odpowiedź, ale to też nie działa –

+0

Powoduje to błąd: ** Menedżer pakietów: nieprzyznawanie pozwolenia android.permission.BLUETOOTH_PRIVILEGED na pakiet com.myapp.me (protectionLevel = 18 flag = 0x3848be46) ** –

-1
<uses-sdk 
    android:minSdkVersion="14" 
    android:targetSdkVersion="21" /> 

Jaki jest twój cel wersja SDK? Czy Twoja aplikacja obsługuje Lollipop?

+0

Tak, obsługuje on lolipop,

+0

Problem nadal istnieje –

Powiązane problemy