Open sokhornhoun opened 8 years ago
Pls give example code for receive the geofence from background ..
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
}
}
}
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());
}
}`
How to capture the Geofence transitions without the app running by intent service. you can just tell how to hook up to intent service. please give example.
thanks,