7

I'm trying to use the activity recognition in a project to detect when the user is "IN-VEHICLE".(Driving) The problem is that it is almost impossibly to use it, as mostProbableActivity often report "IN-VEHICLE" even though I've been sitting at my desk for a long time or just walking around in my house. It would be very nice to know how the API conclude this.

I think this feature has great potential, but as now something is clearly not working.

This is a log of MostProbableActivity taken every 30 seconds to show what I mean. Sitting at my desk, after 4 minutes I turn the phone a couple of times, and this results in a "mostProbable IN-VEHICLE" result.

I've tried different phones and the result is the same. So I don't think it's hardware related.

DetectedActivity [type=STILL, confidence=43]
DetectedActivity [type=STILL, confidence=54]
DetectedActivity [type=STILL, confidence=100]
DetectedActivity [type=STILL, confidence=100]
DetectedActivity [type=STILL, confidence=69]
DetectedActivity [type=STILL, confidence=100]
DetectedActivity [type=STILL, confidence=92]
DetectedActivity [type=TILTING, confidence=100]
DetectedActivity [type=IN_VEHICLE, confidence=49]
DetectedActivity [type=TILTING, confidence=100]
DetectedActivity [type=STILL, confidence=51]
DetectedActivity [type=STILL, confidence=100]
DetectedActivity [type=STILL, confidence=100]
DetectedActivity [type=STILL, confidence=85]
DetectedActivity [type=STILL, confidence=100]
DetectedActivity [type=STILL, confidence=66]
DetectedActivity [type=STILL, confidence=100]

This is the code, nothing special there:

public class ActivitiesIntentService extends IntentService {


    private static final String TAG = "ActivitiesIntentService";


    public ActivitiesIntentService() {
        super(TAG);
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
        Intent i = new Intent(Constants.STRING_ACTION);


        DetectedActivity mostProbableActivity = result.getMostProbableActivity();


        i.putExtra("MOST_PROBABLE_ACTIVITY",mostProbableActivity);



        LocalBroadcastManager.getInstance(this).sendBroadcast(i);


        Log.e(TAG, String.valueOf(mostProbableActivity));
        }

}

From this link:

Activity Recognition API

I can see that others have similar experience, but some claims that it works OK.

I think this is a bug in the confidence algorithm of the API. It should be easy to conclude that the phone isn't moving in any direction, nor on a road so obviously NOT "mostProbable" in a VEHICLE.

Can anyone confirm this problem or do I use it the wrong way?

Best regards

Thomas

Community
  • 1
  • 1
user857558
  • 167
  • 1
  • 2
  • 7
  • 1
    You are using it the right way. The problem is that without sampling the gps and draining the battery it will be very hard to detect driving activity. Google probably tracks the sensors data (accelerometer, gyro, magnetometer etc...) in some periods and looks for a pattern of driving (which is very similar to still but has a unique vibration). Sometimes the algorithm is just not precise enough. – MikeL Apr 30 '16 at 11:31
  • From my testing, the STILL category seems the most reliable, as long as the device has, in fact, been still for several seconds (i.e. for at least around 10 seconds). That has limited utility, but there may be some applicable scenarios for it. – Michael Osofsky Apr 13 '18 at 23:17

2 Answers2

5

Bear in mind that this is a very low-energy consumption service, so it can't be looking at the device sensors constantly. That would drain the battery too quickly to be useful. Be sure to read the docs to understand the constraints.

If you want more accurate readings, increase your detection interval. That will give it more data to work with.

Also bear in mind these measurements are to be taken broadly. A possible use case is to estimate how much time the carrier of the device has been engaged in physical activity, or to activate and deactivate components of an app that should be running when the carrier is doing one of the detected activities.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
3

If you need more accurate readings you should increase the detection level of your device, but this, in turn, would end up draining your battery. As far as the responses of your results are concerned, to be assured that your user is performing a certain activity, the Google Play services’ confidence must be >75 or it would be safe to assume that your user isn’t performing it. In your case, the Google Play services confidence is 49, which means it is not sure whether your user is driving. You could also try using a simple ‘IF STATEMENT’

if(DetectedActivity == “In_Vehicle” && result.getConfidence()> 75)
 {
 // output = User is Driving;
 // Perform task 
 }

Other ways to get more accurate insights about your user’s activities and locations without having your battery drained, is to try some of the API's like tranql, Context Hub or Neura

johndaly
  • 115
  • 7
  • 2
    How did you reach the conclusion that 75% is a good number? Is there some reference to support your suggestion? – Pranaysharma Jan 07 '17 at 13:51
  • @Pranaysharma good question. I found a tutorial mentioning this 75% but I do not how they picked that number: https://code.tutsplus.com/tutorials/how-to-recognize-user-activity-with-activity-recognition--cms-25851 – nbeuchat Jan 10 '18 at 18:28
  • 75% is mentioned in the video that appears on this google page https://developers.google.com/location-context/activity-recognition/ – A.Alqadomi Jan 14 '18 at 13:55