Jinal Dabhi
Jinal Dabhi

Reputation: 181

How to check whether the device is idle or moving for Android App?

I am a novice to Android.

Thanks JD

Upvotes: 3

Views: 1349

Answers (2)

Thamilvanan
Thamilvanan

Reputation: 189

You can achieve this using Activity Recognition API in android. There are various activity to identify. https://developer.android.com/guide/topics/location/transitions

Upvotes: 2

Manohar
Manohar

Reputation: 23394

Save last sent latitude and longitude in shared prefs and calculate distance between last location and current location , If distance is more then update new location to server .

To calculate distance use this function

 private float calculateLocationDifference() {
    float[] dist = new float[1];
    Location.distanceBetween(lastLocation.getLatitude(), lastLocation.getLongitude(), currentLocation.getLatitude(), currentLocation.getLongitude(), dist);
    return dist[0];
}

Please do note that getting location continuously will drain the user battery faster .

Upvotes: 3

Related Questions