alexkendall / react-native-bluetooth-cross-platform

Cross-Platform Bluetooth & WiFi React Native Module. Powered by underdark http://underdark.io/.
179 stars 35 forks source link

"Attempt to invoke virtual method 'java.lang.String android.bluetooth.Bluetooth.Adapter.getName()" #27

Closed bqkhiem96 closed 6 years ago

bqkhiem96 commented 6 years ago

How may the issue got resolved? image

HZSamir commented 6 years ago

You are probably running on an emulator or device that doesn't have Bluetooth. That is why it is throwing this error as it can't get its name. If you have no way around it, and wish to get rid of Bluetooth support altogether this is a quick fix

For android: Edit this file: ./node_modules/react-native-bluetooth-cross-platform/android/src/main/java/com/rctunderdark/NetworkCommunicator.java

At line 25, replace:

private String displayName = BluetoothAdapter.getDefaultAdapter().getName();

by whatever name:

private String displayName = "Whatever"

This will fix the error, but disable bluetooth. Or better yet, try...catch to see if Bluetooth is available then get its name

The same procedure should work for IOS, even though I have never tried it. Hope it helps.

bqkhiem96 commented 6 years ago

thank you for the solution, I'm closing this issue for now