运行新的Bluetooth Low Energy示例会导致RuntimeException



我已经在Android 4.3蓝牙低能耗示例中实现了查找设备的代码。

             final BluetoothManager bluetoothManager =
             (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
        BluetoothAdapter mBluetoothAdapter = bluetoothManager.getAdapter();
        mBluetoothAdapter.startLeScan(mLeScanCallback);

我的舱单包括

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

并且该设备是Nexus 4,该Nexus 4已经闪烁有工厂4.3的图像。

我曾经让这个东西工作过一次,但在随后的运行中,我得到了以下错误:

07-25 19:35:09.216 3308-3308/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.voltagex.adamtestapp/org.voltagex.adamtestapp.BluetoothTestActivity}: java.lang.SecurityException: Need BLUETOOTH permission: Neither user 10148 nor current process has android.permission.BLUETOOTH.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.SecurityException: Need BLUETOOTH permission: Neither user 10148 nor current process has android.permission.BLUETOOTH.
at android.os.Parcel.readException(Parcel.java:1431)
at android.os.Parcel.readException(Parcel.java:1385)
at android.bluetooth.IBluetoothGatt$Stub$Proxy.registerClient(IBluetoothGatt.java:708)
at android.bluetooth.BluetoothAdapter.startLeScan(BluetoothAdapter.java:1487)
at android.bluetooth.BluetoothAdapter.startLeScan(BluetoothAdapter.java:1448)
at org.voltagex.adamtestapp.BluetoothTestActivity.onCreate(BluetoothTestActivity.java:103)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
... 11 more
07-25 20:13:17.567 1219-25094/? E/BtGatt.GattService: getService() - Service requested, but not available!
07-25 20:13:29.210 1219-1219/? E/bt-btif: btif_enable_service: current services:0x100040
07-25 20:13:29.210 1219-1219/? E/bt-btif: btif_enable_service: current services:0x140040
07-25 20:13:29.220 1219-1219/? E/bt-btif: btif_enable_service: current services:0x140040
07-25 20:13:29.880 1219-5621/? E/bt-btm: BTM_SecRegister:p_cb_info->p_le_callback == 0x730d7629
07-25 20:13:29.880 1219-5621/? E/bt-btm: BTM_SecRegister: btm_cb.api.p_le_callback = 0x730d7629
07-25 20:13:29.891 1219-5593/? E/bt-btif: Calling BTA_HhEnable
07-25 20:13:29.891 1219-5593/? E/bt-btif: ## btif_config_get assert section && *section && key && *key && name && *name && bytes && type failed at line:182 ##
07-25 20:13:29.891 1219-5593/? E/bt-btif: ## btif_config_get assert section && *section && key && *key && name && *name && bytes && type failed at line:182 ##
07-25 20:13:29.891 1219-5593/? E/bt-btif: btif_storage_get_adapter_property service_mask:0x140040
07-25 20:13:29.891 1219-5593/? E/bt-btif: ## btif_config_get assert section && *section && key && *key && name && *name && bytes && type failed at line:182 ##
07-25 20:13:29.901 1219-5624/? E/bt_mct: hci lib postload completed
07-25 20:13:29.941 1219-5626/? E/BluetoothServiceJni: SOCK FLAG = 1 ***********************
07-25 20:13:29.981 1219-5631/? E/BluetoothServiceJni: SOCK FLAG = 0 ***********************
07-25 20:14:27.142 5765-5765/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException
at org.voltagex.adamtestapp.BluetoothTestActivity$2$1.run(BluetoothTestActivity.java:120)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

尝试将uses功能标记添加到清单中。因此Android将知道并期待此功能可用:

<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>

相关内容

  • 没有找到相关文章

最新更新