Pls give example code for receive the geofence from background .. I was follow your readme steps to add the broad cast receiver , but not get any update from geofence's . I am already using google sample app for geofence its working fine with my lat, lon .
I have register the brodcast receiver in manifest ...
`
`
And my broadcast receiver is ,
`public class GeoFenceReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (BROADCAST_INTENT_ACTION.equals(intent.getAction())) {
final int transitionType = intent.getIntExtra(TRANSITION_EXTRA_ID, -1);
final List geofencingIds = intent.getStringArrayListExtra(GEOFENCES_EXTRA_ID);
Location location = intent.getParcelableExtra(LOCATION_EXTRA_ID);
Toast.makeText(context, getTransitionNameFromType(transitionType), Toast.LENGTH_SHORT).show();
sendNotification(getTransitionNameFromType(transitionType),context);
for (final String geofenceId : geofencingIds) {
}
}
}
private String getTransitionNameFromType(int transitionType) {
switch (transitionType) {
case Geofence.GEOFENCE_TRANSITION_ENTER:
return "enter";
case Geofence.GEOFENCE_TRANSITION_EXIT:
return "exit";
default:
return "dwell";
}
}
/**
* Posts a notification in the notification bar when a transition is detected.
* If the user clicks the notification, control goes to the MainActivity.
*/
private void sendNotification(String notificationDetails,Context context) {
// Create an explicit content Intent that starts the main Activity.
Intent notificationIntent = new Intent(context, MainActivity.class);
// Construct a task stack.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
// Add the main Activity to the task stack as the parent.
stackBuilder.addParentStack(MainActivity.class);
// Push the content Intent onto the stack.
stackBuilder.addNextIntent(notificationIntent);
// Get a PendingIntent containing the entire back stack.
PendingIntent notificationPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
// Get a notification builder that's compatible with platform versions >= 4
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
// Define the notification settings.
builder.setSmallIcon(R.drawable.ic_menu_share)
// In a real app, you may want to use a library like Volley
// to decode the Bitmap.
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
R.drawable.ic_menu_slideshow))
.setColor(Color.RED)
.setContentTitle("iAttention")
.setContentText(notificationDetails)
.setContentIntent(notificationPendingIntent);
// Dismiss notification once the user touches it.
builder.setAutoCancel(true);
// Get an instance of the Notification manager
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Issue the notification
mNotificationManager.notify(0, builder.build());
}
Pls give example code for receive the geofence from background .. I was follow your readme steps to add the broad cast receiver , but not get any update from geofence's . I am already using google sample app for geofence its working fine with my lat, lon .
I have register the brodcast receiver in manifest ...
`
`
And my broadcast receiver is , `public class GeoFenceReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (BROADCAST_INTENT_ACTION.equals(intent.getAction())) { final int transitionType = intent.getIntExtra(TRANSITION_EXTRA_ID, -1); final List geofencingIds = intent.getStringArrayListExtra(GEOFENCES_EXTRA_ID);
Location location = intent.getParcelableExtra(LOCATION_EXTRA_ID);
Toast.makeText(context, getTransitionNameFromType(transitionType), Toast.LENGTH_SHORT).show();
sendNotification(getTransitionNameFromType(transitionType),context);
for (final String geofenceId : geofencingIds) {
}`