Search code examples
androidbluetoothimageviewstatusstatusbar

Bluetooth status on statusbar


I have my own application home screen as default home screen for my android device. I have a status bar in my application and I am managing the Bluetooth connection status with an Imageview(onclick) in that status bar.

If I click on the Imageview in my statusbar I am turning the bluetooth on/off. I am changing the background of imageview according to the status of bluetooth.

If bluetooth is ON - Blueimage

If bluetooth is OFF - greyImage

So my question is - If I enable/disable the bluetooth in bluetoth settings page and press the back button and navigate to my home screen then Imageview(background image) in my status bar should get changed automatically.

I tried a lot updating the image of imageview on back button press(by overriding onbackpressed method) but no result.

Is there any similar API with which we can read/store the status of bluetooth in a variable as soon as we enable/disable the bluetooth in bluetooth settings page and according to that the status bar imageview backround will get changed automatically?

Any help is greatly appreciated, Thanks


Solution

  • you can put the code that checked for the Bluetooth status in the onRestart() method

    like this:

    public class yourClass {
    
     public void onCreate(Bundle savedInstanceState) {
    
     // your code
     }
    
     public void onRestart() {
    
     // put the checked code for the Bluetooth status here  
     }