Invalid activities specified in the ActivityTransitionRequest
M

3

6

I'm trying to use ActivityRecognition. However I get an error when i'm trying to get a transition update for DetectedActivity.TILTING or DetectedActivity.UNKNOWN. For all the other activity types I don't have problems.

Here is my code to create the ActivityTransitionRequest

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent intent = new Intent(this, ActivityRecognizedService.class);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, 0);

    Task<Void> task =
            ActivityRecognition.getClient(this).
                    requestActivityTransitionUpdates(createTransitionsRequest(), pendingIntent);

    task.addOnSuccessListener(
            new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void result) {
                    Log.d(TAG, "success");
                    // Handle success
                }
            }
    );

    task.addOnFailureListener(
            new OnFailureListener() {
                @Override
                public void onFailure(Exception e) {
                    Log.d(TAG, "failure", e);
                    // Handle error
                }
            }
    );

    // ActivityRecognition.getClient(this).requestActivityUpdates(1000L, pendingIntent);
}

private ActivityTransitionRequest createTransitionsRequest() {
    List<ActivityTransition> transitions = new ArrayList<>();

    transitions.add(
            new ActivityTransition.Builder()
                    .setActivityType(DetectedActivity.IN_VEHICLE)
                    .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
                    .build());

    transitions.add(
            new ActivityTransition.Builder()
                    .setActivityType(DetectedActivity.IN_VEHICLE)
                    .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_EXIT)
                    .build());

    transitions.add(
            new ActivityTransition.Builder()
                    .setActivityType(DetectedActivity.STILL)
                    .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
                    .build());

    transitions.add(
            new ActivityTransition.Builder()
                    .setActivityType(DetectedActivity.STILL)
                    .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_EXIT)
                    .build());

    transitions.add(
            new ActivityTransition.Builder()
                    .setActivityType(DetectedActivity.ON_FOOT)
                    .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
                    .build());

    transitions.add(
            new ActivityTransition.Builder()
                    .setActivityType(DetectedActivity.ON_FOOT)
                    .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_EXIT)
                    .build());

    transitions.add(
            new ActivityTransition.Builder()
                    .setActivityType(DetectedActivity.WALKING)
                    .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
                    .build());

    transitions.add(
            new ActivityTransition.Builder()
                    .setActivityType(DetectedActivity.WALKING)
                    .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_EXIT)
                    .build());

    transitions.add(
            new ActivityTransition.Builder()
                    .setActivityType(DetectedActivity.RUNNING)
                    .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
                    .build());

    transitions.add(
            new ActivityTransition.Builder()
                    .setActivityType(DetectedActivity.RUNNING)
                    .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_EXIT)
                    .build());

    transitions.add(
            new ActivityTransition.Builder()
                    .setActivityType(DetectedActivity.ON_BICYCLE)
                    .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
                    .build());

    transitions.add(
            new ActivityTransition.Builder()
                    .setActivityType(DetectedActivity.ON_BICYCLE)
                    .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_EXIT)
                    .build());

    // The following activity transitions will result in an exception.
    transitions.add(
            new ActivityTransition.Builder()
                    .setActivityType(DetectedActivity.UNKNOWN)
                    .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
                    .build());

    transitions.add(
            new ActivityTransition.Builder()
                    .setActivityType(DetectedActivity.UNKNOWN)
                    .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_EXIT)
                    .build());

    transitions.add(
            new ActivityTransition.Builder()
                    .setActivityType(DetectedActivity.TILTING)
                    .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
                        .build());

    transitions.add(
            new ActivityTransition.Builder()
                    .setActivityType(DetectedActivity.TILTING)
                    .setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_EXIT)
                        .build());

    return new ActivityTransitionRequest(transitions);
}

This is the IntentService I'm using.

public class ActivityRecognizedService extends IntentService {
    private static final String TAG = ActivityRecognizedService.class.getSimpleName();

    public ActivityRecognizedService() {
        super("ActivityRecognizedService");
    }

    public ActivityRecognizedService(String name) {
        super(name);
    }

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
        if(ActivityRecognitionResult.hasResult(intent)) {
            ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
            handleDetectedActivities( result.getProbableActivities() );
        }
    }

    private void handleDetectedActivities(List<DetectedActivity> probableActivities) {
        for( DetectedActivity activity : probableActivities ) {
            switch( activity.getType() ) {
                case DetectedActivity.IN_VEHICLE: {
                    Log.e( TAG, "In Vehicle: " + activity.getConfidence() );
                    break;
                }
                case DetectedActivity.ON_BICYCLE: {
                    Log.e( TAG, "On Bicycle: " + activity.getConfidence() );
                    break;
                }
                case DetectedActivity.ON_FOOT: {
                    Log.e( TAG, "On Foot: " + activity.getConfidence() );
                    break;
                }
                case DetectedActivity.RUNNING: {
                    Log.e( TAG, "Running: " + activity.getConfidence() );
                    break;
                }
                case DetectedActivity.STILL: {
                    Log.e( TAG, "Still: " + activity.getConfidence() );
                    break;
                }
                case DetectedActivity.TILTING: {
                    Log.e( TAG, "Tilting: " + activity.getConfidence() );
                    break;
                }
                case DetectedActivity.WALKING: {
                    Log.e( TAG, "Walking: " + activity.getConfidence() );
                    break;
                }
                case DetectedActivity.UNKNOWN: {
                    Log.e( TAG, "Unknown: " + activity.getConfidence() );
                    break;
                }
            }
        }
    }
}

This is the exception i'm getting:

    com.google.android.gms.common.api.ApiException: 10: SecurityException: Invalid activities specified in the ActivityTransitionRequest! at com.google.android.gms.common.internal.zzb.zza(Unknown Source)
                                                                         at com.google.android.gms.common.internal.zzbk.zza(Unknown Source)
                                                                         at com.google.android.gms.common.internal.zzbl.zza(Unknown Source)
                                                                         at com.google.android.gms.common.api.internal.BasePendingResult.zzc(Unknown Source)
                                                                         at com.google.android.gms.common.api.internal.BasePendingResult.zza(Unknown Source)
                                                                         at com.google.android.gms.common.api.internal.zzm.zzc(Unknown Source)
                                                                         at com.google.android.gms.common.api.internal.zzc.zza(Unknown Source)
                                                                         at com.google.android.gms.common.api.internal.zzbo.zzb(Unknown Source)
                                                                         at com.google.android.gms.common.api.internal.zzbo.zzo(Unknown Source)
                                                                         at com.google.android.gms.common.api.internal.zzbo.onConnected(Unknown Source)
                                                                         at com.google.android.gms.common.internal.zzac.zza(Unknown Source)
                                                                         at com.google.android.gms.common.internal.zzn.zza(Unknown Source)
                                                                         at com.google.android.gms.common.internal.zze.zza(Unknown Source)
                                                                         at com.google.android.gms.common.internal.zzi.zzc(Unknown Source)
                                                                         at com.google.android.gms.common.internal.zzh.handleMessage(Unknown Source)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                         at android.os.Looper.loop(Looper.java:154)
                                                                         at android.os.HandlerThread.run(HandlerThread.java:61)

Any help would be appreciated.

Misery answered 25/3, 2018 at 11:32 Comment(6)
which class does ActivityRecognizedService extend ??Spearwort
@SantanuSur IntentServiceMisery
lel IntentService is a Service NOT an activity, how are you using requestActivityTransitionUpdates method with it ??Spearwort
@SantanuSur I'm not sure what your telling me. I've updated my question with the code for the IntentService. Can you tell me what i should change?Misery
For all the other activity types I don't have problems ...are you using the same pendingIntent along with them ?? i mean Intent intent = new Intent(this, ActivityRecognizedService.class);Spearwort
@SantanuSur Yes its all the same PendingIntent. Actually I'm not receiving any intent yet in my service with requestActivityTransitionUpdates. However it works with 'requestActivityUpdates' so I think that the service is not the problem.Misery
J
13

As per official android developer document,

The Transition API supports the following activities:

IN_VEHICLE
ON_BICYCLE
RUNNING
STILL
WALKING
Jori answered 31/3, 2018 at 9:45 Comment(0)
H
1

The Transition API supports only the following activities: - IN_VEHICLE - ON_BICYCLE - RUNNING - STILL - WALKING

Habit answered 29/3, 2018 at 10:35 Comment(1)
Welcome to StackOverflow! Please have a look at How do I write a good answer?Suter
C
0

Remove the Transition for UNKNOWN and TILTING. They are not supported.

Crook answered 20/7, 2023 at 15:15 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Playtime

© 2022 - 2024 — McMap. All rights reserved.