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
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 } 1 Comment
TheJudge
Be careful, on some devices this might crash due to NoClassDefNotFound for BluetoothManager
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
Anonimys
Note getPackageManager() you can get by 2 way: 1) context.getPackageManager(); or 2) getActivity().getPackageManager()