7

Is there any way to check is a device has a bluetooth adapter or not? I have a tablet that not has a bluetooth. So how can I handle that?

3 Answers 3

12

Add permission to Manifest

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

Code for Activity

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter == null) { //handle the case where device doesn't support Bluetooth } else { //bluetooth supported } 
Sign up to request clarification or add additional context in comments.

1 Comment

Be careful, on some devices this might crash due to NoClassDefNotFound for BluetoothManager
6

For completeness, I think you can also do something like this:

getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) 

And I presume this for normal bluetooth:

getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH) 

Not sure if this is more optimal then requesting adapter thou.

1 Comment

Note getPackageManager() you can get by 2 way: 1) context.getPackageManager(); or 2) getActivity().getPackageManager()
2

You can simply check if you can get its default BluetoothAdapter or not.

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter == null) { //handle the case where device doesn't support Bluetooth } else { //bluetooth supported } 

Hope this helps.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.