Why do we get a throwable when we try to get the BluetoothManager service?

Viewed 70

I'm writing an app in Android studio which needs to use Bluetooth services. In onCreate in MainActivity, I try to open the BluetoothManager like this:

BluetoothManager bluetoothManager = getSystemService(BluetoothManager.class);

But I receive a throwable

D/BluetoothAdapter: java.lang.Throwable
        at android.bluetooth.BluetoothAdapter.<init>(BluetoothAdapter.java:762)
        at android.bluetooth.BluetoothAdapter.getDefaultAdapter(BluetoothAdapter.java:735)
        at android.bluetooth.BluetoothManager.<init>(BluetoothManager.java:72)
        at android.app.SystemServiceRegistry$10.createService(SystemServiceRegistry.java:325)
        at android.app.SystemServiceRegistry$10.createService(SystemServiceRegistry.java:322)
        at android.app.SystemServiceRegistry$CachedServiceFetcher.getService(SystemServiceRegistry.java:1722)
        at android.app.SystemServiceRegistry.getSystemService(SystemServiceRegistry.java:1402)
        at android.app.ContextImpl.getSystemService(ContextImpl.java:1956)
        at androidx.appcompat.view.ContextThemeWrapper.getSystemService(ContextThemeWrapper.java:167)
        at android.view.ContextThemeWrapper.getSystemService(ContextThemeWrapper.java:188)
        at android.app.Activity.getSystemService(Activity.java:6816)
        at android.content.Context.getSystemService(Context.java:3705)

It's not critical, and it does return a BluetoothManager but still shouldn't show up, should it?

I also tried :

BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);

My manifest

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
0 Answers
Related