title: android check if bluetooth is on/off
body: <p>I made a sms reciever text to speach, they talk only if bluetooth is on and connect in boardcast. I look on google and the tutorial found tell me how to connect but i can't find the right one to check if is on or off. I start with </p>
  
  <pre><code>if (bluetooth == on){
  //do some stuff.
  }
  else {
  // do other stuff
  </code></pre>
  
  <p>This is my code if it may help you to understand :</p>
  
  <pre><code>import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.telephony.SmsManager;
  import android.telephony.SmsMessage;
  
  
   public class RecevoirSms extends BroadcastReceiver
  {
  final SmsManager sms = SmsManager.getDefault();
  
  @Override
  public void onReceive(Context context, Intent intent) 
  {
      final Bundle bundle = intent.getExtras();          
      final Object[] pdusObj = (Object[]) bundle.get("pdus");         
      for (int i = 0; i &lt; pdusObj.length; i++) {                      
      SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);     
      String phoneNumber = currentMessage.getDisplayOriginatingAddress();            
      String senderNum = phoneNumber;             
      String Message = currentMessage.getDisplayMessageBody();   
  
   if (senderNum.contains("3330") || senderNum.contains("5149921188") || senderNum.contains("9000"))   {
  }
  
   else {
  
      String word = senderNum;
      String remove ="+1";
      String Numero = (removeWords(word, remove));
      MemoireCourtTerme.Nsms =  Numero;  
      MemoireCourtTerme.Message = Message;
  
      if (Message.contains("eva") &amp;&amp; Message.contains("?") || Message.contains("Eva") &amp;&amp; Message.contains("?")){
         Intent i2 = new Intent(context,EvaSms.class); 
         i2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
         context.startActivity(i2); 
      }
  
      else {
             MemoireCourtTerme.Mode = "SmsRecu";
             MemoireCourtTerme.ReponceEva = "Vous avez reçu un nouveau message voulez vous l'écoutez?";
             MemoireCourtTerme.ReponceEvaDuree = "5000";
             Intent i2 = new Intent(context,Parole.class); 
             i2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
             context.startActivity(i2); 
          }
  
  
              }                         
  }
  }
  public static String removeWords(String word, String remove){
      return word.replace(remove, "");
  }
  }
  </code></pre>