title: Android : Geo Fencing Receiver not calling
body: <p>I just made a demo for the Geo Fencing in android as per the documentation but here Geo Fencing Broadcast Receiver is not calling when I go out from the fence area or entered into it.</p>
  
  <p>Guys look the code and try to catch the issue.</p>
  
  <p>Thanks Kingo</p>
  
  <p>SplashActivity.java</p>
  
  <pre><code>public class SplashActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          List&lt;Geofence&gt; mCurrentGeofences = new ArrayList&lt;Geofence&gt;();
  
          SimpleGeofence mUIGeofence1 = new SimpleGeofence("1",
          // Get latitude, longitude, and radius from the UI
                  26.87473379143512, 75.78373555021025, 1,
                  // Set the expiration time
                  Geofence.NEVER_EXPIRE,
                  // Only detect entry transitions
                  Geofence.GEOFENCE_TRANSITION_ENTER);
  
          /*
           * Add Geofence objects to a List. toGeofence() creates a Location
           * Services Geofence object from a flat object
           */
          mCurrentGeofences.add(mUIGeofence1.toGeofence());
  
          // Start the request. Fail if there's already a request in progress
          try {
              // Try to add geofences
              GeofenceRequester mGeofenceRequester = new GeofenceRequester(this);
              mGeofenceRequester.addGeofences(mCurrentGeofences);
          } catch (UnsupportedOperationException e) {
          }
  
      }
  }
  </code></pre>
  
  <p>GeoFenceRequestor.java</p>
  
  <pre><code>private PendingIntent createRequestPendingIntent() {
  
      // If the PendingIntent already exists
      if (null != mGeofencePendingIntent) {
  
          // Return the existing intent
          return mGeofencePendingIntent;
  
          // If no PendingIntent exists
      } else {
  
          // Create an Intent pointing to the IntentService
          Intent intent = new Intent(
                  "com.example.demo.ACTION_RECEIVE_GEOFENCE");
  
          // MAKE SURE YOU CHANGE THIS TO getBroadcast if you are coming from
          // the sample code.
          return PendingIntent.getBroadcast(mActivity, 0, intent,
                  PendingIntent.FLAG_UPDATE_CURRENT);
      }
  }
  
  
  @Override
  public void onAddGeofencesResult(int statusCode, String[] geofenceRequestIds) {
  
      // Create a broadcast Intent that notifies other components of success
      // or failure
      Intent broadcastIntent = new Intent();
  
      // Temp storage for messages
      String msg;
  
      // If adding the geocodes was successful
      if (LocationStatusCodes.SUCCESS == statusCode) {
  
          // Create a message containing all the geofence IDs added.
          msg = mActivity.getString(R.string.add_geofences_result_success,
                  Arrays.toString(geofenceRequestIds));
  
          // In debug mode, log the result
          Log.d(GeofenceUtils.APPTAG, msg);
  
          // Create an Intent to broadcast to the app
          broadcastIntent.setAction(GeofenceUtils.ACTION_GEOFENCES_ADDED)
                  .addCategory(GeofenceUtils.CATEGORY_LOCATION_SERVICES)
                  .putExtra(GeofenceUtils.EXTRA_GEOFENCE_STATUS, msg);
          // If adding the geofences failed
      } else {
  
          /*
           * Create a message containing the error code and the list of
           * geofence IDs you tried to add
           */
          msg = mActivity.getString(R.string.add_geofences_result_failure,
                  statusCode, Arrays.toString(geofenceRequestIds));
  
          // Log an error
          Log.e(GeofenceUtils.APPTAG, msg);
  
          // Create an Intent to broadcast to the app
          broadcastIntent.setAction(GeofenceUtils.ACTION_GEOFENCE_ERROR)
                  .addCategory(GeofenceUtils.CATEGORY_LOCATION_SERVICES)
                  .putExtra(GeofenceUtils.EXTRA_GEOFENCE_STATUS, msg);
      }
  
      // Broadcast whichever result occurred
      LocalBroadcastManager.getInstance(mActivity).sendBroadcast(
              broadcastIntent);
  
      // Disconnect the location client
      requestDisconnection();
  }
  </code></pre>
  
  <p>GeofenceReceiver.java</p>
  
  <p>public class GeofenceReceiver extends BroadcastReceiver {
          Context context;</p>
  
  <pre><code>    Intent broadcastIntent = new Intent();
  
      @Override
      public void onReceive(Context context, Intent intent) {
          this.context = context;
  
          broadcastIntent.addCategory(GeofenceUtils.CATEGORY_LOCATION_SERVICES);
          Toast.makeText(context, "Receiver", Toast.LENGTH_LONG).show();
          if (LocationClient.hasError(intent)) {
              handleError(intent);
          } else {
              handleEnterExit(intent);
          }
      }
  }
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.demo"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="10" /&gt;
  
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;meta-data
              android:name="com.facebook.sdk.ApplicationId"
              android:value="@string/app_id" /&gt;
  
          &lt;activity
              android:name=".SplashActivity"
              android:label="@string/title_activity_main" &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;/activity&gt;
  
          &lt;receiver
              android:name=".GeofenceReceiver"
              android:exported="false" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.example.demo.ACTION_RECEIVE_GEOFENCE" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  
          &lt;meta-data
              android:name="com.google.android.gms.version"
              android:value="@integer/google_play_services_version" /&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>It add the Geo Fence successfully but later it does not call the Broadcast receiver to get to know whether entered/exit</p>