Android Geofence – Entry and Exit

Geofencing allows you to send notifications to your users in Android. when they are in the vicinity of, for example, your store. By doing so, you only provide your users with information relevant to them and increase your app usage, foot-traffic and conversion.Using Android Geofencing ,we are identify Exit and Entry point of users. A Geofence is a virtual perimeter around a location. You can create Geofences of 50 to 50.000 meters radius to send location-based notifications to users approaching, for example, your stores, coffee shops or events. Create Geofences Creating Geofences in the Plot Dashboard is as easy as riding your bike. You can search for a place or address and then set the name and radius of the Geofence. Creating Geofences on a map gives you perfect control of where your users will receive your Location Based Notifications. public Geofence toGeofence() { // Build a new Geofence object return new Geofence.Builder() .setRequestId(Long.toString(id)) .setTransitionTypes(transitionType) .setCircularRegion(latitude, longitude, radius) .setExpirationDuration(expirationDuration) .build(); } Geofence Enter When user exit the geofence , user getting trigger and showing that you are entering geofence. public class ReceiveTransitionsIntentService extends IntentService { @Override protected void onHandleIntent(Intent intent) { int transition = LocationClient.getGeofenceTransition(intent); if ((transition == Geofence.GEOFENCE_TRANSITION_ENTER) || (transition == Geofence.GEOFENCE_TRANSITION_EXIT)){ if (transition == Geofence.GEOFENCE_TRANSITION_ENTER) { //bussiness logic AlarmManager alarmManager=(AlarmManager)getSystemService(Context.ALARM_SERVice); Intent broadcast_intent = new Intent(this, GeofencigNotificationReciever.class); broadcast_intent.putExtra("EventId", eventId); //data to pass broadcast_intent.putExtra("TransitionType", transitionType); PendingIntent pendingIntent=PendingIntent.getBroadcast(this, 0, broadcast_intent, 0); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), pendingIntent); } } } }   Geofence Exit When user exit the geofence,user getting trigger and showing that you are exit geofence. public class ReceiveTransitionsIntentService extends IntentService { protected void onHandleIntent(Intent intent) { int transition = LocationClient.getGeofenceTransition(intent);...

Android Push Notifications using GCM

“Google Cloud Messaging for Android (GCM) is a service that helps developers send data from servers to their Android applications on Android devices”. Using this service you can send data to your application whenever new data is available instead of making requests to server in timely fashion. Integrating GCM in your android application enhances user experience and saves lot of battery power. Google Cloud Messaging GCM API We can use GCM as a notification engine. On an event it will send a notification to an android application and vice-versa. A notification is a small piece of information. Using GCM, maximum 4kb of payload can be sent in a notification. For now GCM is a free service – lets use responsibly 🙂 Android App can receive the message from Google cloud messaging server (GCM) even if the app is not running via Intent broadcasting (our example app will demonstrate this). Manifest Let’s start with our manifest. We’ll want to add some permissions under the manifest markup. <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission android:name="your.package.name.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="your.package.name.permission.C2D_MESSAGE" /> Next step is to register our Broadcast Receiver and Service. You should already have that last line in your manifest if you added the google play services properly. <receiver android:name=".GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="your.package.name" /> </intent-filter> </receiver> <service android:name=".GcmIntentService" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> Broadcast Receiver We are going to start by creating a new class which extends WakefulBroadcastReceiver. public class GcmBroadcastReceiver extends WakefulBroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName()); startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK); } } The...