-2

I am developing and app which uses bluetooth communication. I need to have an icon to show if bluetooth is connected or not at all times in the action bar. How can I implement this?

The check on BluetoothSocket mmSocket

 if(mmSocket==null) 

can be called in methods. Is there a way to check this continuously while the app is running ?

Prat
  • 67
  • 7
  • Why don't you ask Google? Questions like yours are not suited very well for Stack Overflow. – Xaver Kapeller Jul 21 '14 at 07:20
  • possible duplicate of [How to enable/disable bluetooth programmatically in android](http://stackoverflow.com/questions/3806536/how-to-enable-disable-bluetooth-programmatically-in-android) – Minp Jul 21 '14 at 07:22
  • possible duplicate of [How to programmatically tell if a Bluetooth device is connected? (Android 2.2)](http://stackoverflow.com/questions/4715865/how-to-programmatically-tell-if-a-bluetooth-device-is-connected-android-2-2) – Manish Dubey Jul 21 '14 at 07:22
  • @user1170640 This question is not a duplicate of the one you link to. They are about two completely different things. Try to be more careful in the future... – Xaver Kapeller Jul 21 '14 at 07:23
  • http://stackoverflow.com/help/how-to-ask – Droidman Jul 21 '14 at 07:28
  • SO is not a site where people will write code on-demand. Tell us how you imagine to solve your problem, what you have tried, what didn't work, post some code and then you are most likely to get help – Droidman Jul 21 '14 at 07:29
  • @Xaver Kapeller I did google it, couldn't find a proper solution. I've been stuck on this for days now. Was just hoping to get any ideas. – Prat Jul 21 '14 at 07:36

1 Answers1

0

I might give you some help but I will not explain all the thing to you. You have to search a little.

If you don't understand something, Google it or search it on google dev website :)

There is a broadcast here BluetoothAdapter.ACTION_STATE_CHANGED

Register that broadcast and look at the documentation to know what in the BroadcastReceiver will tell you if the bluetooth is ON or OFF.

Please don't forget to unregister your receiver when your activity is paused / destroyed.

Because the broadcast will not tell you on each first launch of the activity if the Bluetooth is ON/OFF (because it is only fired when Bluetooth state changed!), you might want to look at this solution to check the Bluetooth connection state on the fly

How to check if bluetooth is enabled programmatically?

Community
  • 1
  • 1
Tristan
  • 326
  • 2
  • 8