Thursday, January 1, 2015

Android Geofence Stop Getting Transition Events After Some Time

And here comes the first technical blog of 2015, Recently in one of our android application we have used Geofences in Android application. The app needs to track entry and exit of device in Geofence. After implementing and configuring Geofences by help of the sample code from android developer site, it worked good for some time but after the app is running for long time suddenly no transitions were recorded even though the device was in Geofence. After looking for the reason for few hours, I finally found a solution, in this blog I am going to mention that.

The issue was with IntentService mentioned in example code. When your device enters into Geofence, this intent service gets called with pending intent. It works good if your app is in foreground but when the app is in background, this IntentService is never called. So to overcome with this shortcomings, we have used Broadcast receiver in stead of IntentService.

So first define BroadcastReceiver in Manifest file.

<receiver
            android:name="com.app.appname.GeofenceReceiver"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.tracksum.vehicletrack.GeofenceReceiver.ACTION_RECEIVE_GEOFENCE" />
            </intent-filter>

        </receiver>

Now create this class in your package. 

public class GeofenceReceiver extends BroadcastReceiver {

   public void onReceive(Context context, Intent intent) {
       if (LocationClient.hasError(intent)) {
           handleError(intent);
       } else {
           handleEnterExit(intent);
       }
   }

    private void handleError(Intent intent){
       
    }

   private void handleEnterExit(Intent intent) {
       int transition = LocationClient.getGeofenceTransition(intent);
       if (transition == Geofence.GEOFENCE_TRANSITION_ENTER){
           Log.v("geofence","entered");
       }else if(transition == Geofence.GEOFENCE_TRANSITION_EXIT){
           Log.v("geofence","exited");
       }
   }
}

This is your broadcast receiver. Now create an intent and pending intent with this.

Intent intent = new Intent("com.app.appname.GeofenceReceiver.ACTION_RECEIVE_GEOFENCE");

PendingIntent geoFencePendingIntent = PendingIntent.getBroadcast( getApplicationContext(), 0,                                                                             intent, PendingIntent.FLAG_UPDATE_CURRENT);

Add this to location client while adding geofences.

mLocationClient.addGeofences(geofenceList, geoFencePendingIntent, this);

That's it and now you will get all the transitions of Geofence if your app is not in foreground.

Introducing Adsum

Hello,

This is my first blog post of 2015 and this time it's not technical blog. I would like to introduce a product built by our team. Since last few moths we were building this product and finally it's here so here we are introducing our milestone product "ADSUM"

Adsum as the name suggests means "I am present".   Briefly, Adsum is an app on your phone that keeps track of your attendance on day to day basis. It makes the life of the employee and HR easier by creating monthly charts of attendance, absenteeism, leave and sick day and linking it to the employees payroll and has many other benefits.

It's a GPS based attendance & leave management system that helps the Organizations & Managers to manage the resource on the fly. Output from this system can be linked to payroll, expense management system etc. Data is accessible real time and helps you to reduce the conflicts amongst the workforce on attendance and leave management. System can be customized based on your needs and reporting requirements. Following are few screenshots of the application.






It comes with two different views for employees and managers. Managers has extra views like dashboard and activities. App has real time notifications which is sent to managers as soon as employee marks attendance and apply for leaves. Managers can approve leave and attendance form the app it self.This makes their life so easy. 

It's an ideal app for organizations who has staffs which are paid on hourly basis. Using Adsum app you can precisely calculate number of hours worked and you can have monthly and weekly report for payroll. 

In short this is an awesome application for any business who want to automate their attendance management system. If you want this app for your organizations or want to know more about it, kindly contact us. Following are our contact details.

Vibhay Vaidya : +919920465555
Rinkal Shah : +919898171728

Also drop us an email on following email ids.

info@novustouch.com
info@thedesignshop.co.in

Thank you.

Thursday, December 25, 2014

Android Application Get GPS ON/OFF Notification

Hello,

Recently in one of my project we had location service which is used send locations to server and draw a path on map of travel. As we know to get accurate location from the device we need GPS turned on and we wanted to track event and log event on server if user turn off GPS purposefully. In this blog I am going to explain how to do this.

First of all you need to add following permissions to your android manifest file so that your app can access users location.

 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

 <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />

Now create an instance of location manager which receives location updates from GPS. 

locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

As you can see in above code we are creating location manager instance and set it to receive updates from GPS. Now we will add GPS status listener.

locationManager.addGpsStatusListener(new android.location.GpsStatus.Listener()
  {
    public void onGpsStatusChanged(int event)
    {
        switch(event)
        {
        case android.location.GpsStatus.GPS_EVENT_STARTED:
            Log.v("gps","gps is on");
            break;
        case android.location.GpsStatus.GPS_EVENT_STOPPED:
            Log.v("gps","gps is off");
            break;
        }
    }
});

As you can see in above code we have added GPS status listener to location manager. When either GPS is turned on or off onGpsStatusChanged event callback will be called and you can check case as shown in above code and do the stuff in there.

Hope this helps you.