title: Airplane Mode Receiver in Manifest?
body: <p>I am working on developing an Android app that will be used as a handheld controller in an industrial environment. In order to make the tablet less desirable to take home, I was going to try and programatically turn on Airplane Mode all the time but that was deprecated in 4.2, which is also the version we are using in order to have Android Open Accessory. However I was thinking that if I could register a receiver within the manifest such that it will launch my app anytime Airplane Mode is changed and then check if it is off and prompt the user to turn it back on. </p>
  
  <p>I have tried this following solution, also found as the answer to <a href="https://stackoverflow.com/questions/2294971/intent-action-for-network-events-in-android-sdk">this</a> problem.</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;receiver android:name=".receiver.ConnectivityReceiver"&gt;
  &lt;intent-filter&gt;
      &lt;action android:name="android.net.conn.CONNECTIVITY_CHANGE" /&gt;
  &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>
  
  <p>I have also tried this code:</p>
  
  <pre><code>&lt;receiver android:enabled="true" android:name=".ConnectivityReceiver"&gt;
  &lt;intent-filter&gt;
      &lt;action android:name="android.intent.action.SERVICE_STATE"/&gt;
  &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>
  
  <p>also found as an aswer by saxos <a href="https://stackoverflow.com/questions/4319212/how-can-one-detect-airplane-mode-on-android">here</a>.</p>
  
  <p>Now neither of these solutions cause my app to launch when airplane mode is changed. </p>
  
  <p><strong>Is it possible to register a BroadcaseReceiver for Airplane Mode within the manifest file and have that intent launch the app?</strong></p>
  
  <p>Edit 1: I do have the BroadcastReceiver working within the java code so that I can detect this situation while my app is active. That is not what I am looking for though. Thanks.</p>
  
  <p>Edit 2: This is my entire manifest file currently:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.i2c"
  android:versionCode="1"
  android:versionName="1.0" &gt;
  
  &lt;uses-sdk
      android:minSdkVersion="17"
      android:targetSdkVersion="17" 
      android:maxSdkVersion="17"/&gt;
      &lt;!-- SDK 14 = 4.0 ICS
           SDK 17 = 4.2 JB --&gt;             
  
  &lt;!-- Assures software is not loaded onto unsupported screen size, i.e. phones --&gt;
  &lt;supports-screens android:xlargeScreens="true"
      android:largeScreens="true"
      android:normalScreens="false"
      android:smallScreens="false"
      android:anyDensity="true"/&gt;
  
  &lt;uses-feature android:name="android.hardware.usb.accessory"/&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name="com.example.i2c.mainActivity"
          android:label="@string/app_name"  
          android:configChanges="keyboardHidden|orientation|screenSize"
          android:launchMode="singleTask"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"/&gt;
          &lt;/intent-filter&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.AIRPLANE_MODE" /&gt;
          &lt;/intent-filter&gt;
          &lt;meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
              android:resource="@xml/accessory_filter"/&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>The <code>USB_ACCESSORY ATTACHED</code> and the <code>MAIN</code> launcher work just fine and start my app from an <code>onCreate</code> point. However the <code>AIRPLANE_MODE</code> does not seem to do anything. </p>
  
  <p>And here is my BroadcastReceiver that is within the java code:</p>
  
  <pre><code>    private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver(){
      @Override
      public void onReceive(Context context, Intent intent) {
          Log.d("I2CActivity", "onReceive of BroadcastReceiver()");
          String action = intent.getAction();
          if(ACTION_USB_PERMISSION.equals(action)) {
              Log.d("ACTION_USB_PERMISSION", action.toString());
              synchronized (this) {
                  Log.d("syncronized", this.toString());
                  UsbAccessory accessory = (UsbAccessory) intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
                  if(intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
                      if (accessory != null) {
                          OpenAccessory(accessory);
                      }
                  }
                  else {
                      Log.d("mUsbReceiver", "permission denied for accessory " + accessory);
                  }
              }
          }
          else if(UsbManager.ACTION_USB_ACCESSORY_ATTACHED.equals(action)) {
              Log.d("ACTION_USB_ACCESSORY_ATTACHED", action.toString());
              UsbAccessory accessory = (UsbAccessory)intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
              if (accessory != null) {
                  resumeAccessory();
              }
          }
          else if(UsbManager.ACTION_USB_ACCESSORY_DETACHED.equals(action)) {
              Log.d("ACTION_USB_ACCESSORY_DETACHED", action.toString());
              UsbAccessory accessory = (UsbAccessory)intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
              if (accessory != null) {
                  closeAccessory();
              }
          }
          else if(Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) {
              Log.e("Airplane Mode", "Airplane mode changed");
              airplaneMode = Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
          }
      }
  };
  </code></pre>
  
  <p>however from my understanding this is only registered when the app is running, I want a receiver that is registered even when the app is not running. </p>