article

Amelia@Amazon avatar image
Amelia@Amazon posted

How to prevent NullPointerException Issues when using Bluetooth SCO

Summary

When targeting API level 21, a call to startBluetoothSco() (from the android.media.AudioManager package) will throw a NullPointerException unless a bluetooth device is connected to the Android device.

Resolution

There is currently no solution for this issue. But the recommended workaround is to catch the NullPointerException and manage the failed connection appropriately (notify the user, etc).

Sample Code

    try {
    audioManager.startBluetoothSco();
    }catch (NullPointerException e){
    Log.e(“Exceptions","Null Pointer Exception: No bluetooth receiver Connected”);
    } 

Keywords: Bluetooth, NullPointerException, Wireless, Audio

KB_0015

androidlollipop
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Article

Contributors

brizzlebrazzle contributed to this article