Skip to content
TheChatArchiveThe Chat Archive
o1-preview-2024-09-12· OpenAIAi2 WildChat-4.8M (AI2)

i`ve got errors when start activity recognition service of android app: 2024-09-23…

  1. User

    i`ve got errors when start activity recognition service of android app: 2024-09-23 00:01:29.447 15187-15187 ActivityRe...ionService com.google.sl E Failed to start activity updates (Ask Gemini) java.lang.SecurityException: ActivityTransitionRequest specified an unsupported transition activity type. at android.os.Parcel.createExceptionOrNull(Parcel.java:3182) at android.os.Parcel.createException(Parcel.java:3166) at android.os.Parcel.readException(Parcel.java:3149) at android.os.Parcel.readException(Parcel.java:3091) at com.google.android.gms.internal.location.zza.zzc(com.google.android.gms:play-services-location@@21.2.0:3) at com.google.android.gms.internal.location.zzu.zzj(com.google.android.gms:play-services-location@@21.2.0:5) at com.google.android.gms.internal.location.zzal.accept(com.google.android.gms:play-services-location@@21.2.0:7) at com.google.android.gms.common.api.internal.zacv.doExecute(com.google.android.gms:play-services-base@@18.4.0:1) at com.google.android.gms.common.api.internal.zag.zaf(com.google.android.gms:play-services-base@@18.4.0:1) at com.google.android.gms.common.api.internal.zabq.zaK(com.google.android.gms:play-services-base@@18.4.0:2) at com.google.android.gms.common.api.internal.zabq.zaM(com.google.android.gms:play-services-base@@18.4.0:4) at com.google.android.gms.common.api.internal.zabq.zaG(com.google.android.gms:play-services-base@@18.4.0:3) at com.google.android.gms.common.api.internal.zabq.zaH(com.google.android.gms:play-services-base@@18.4.0:13) at com.google.android.gms.common.api.internal.zabq.onConnected(com.google.android.gms:play-services-base@@18.4.0:2) at com.google.android.gms.common.internal.zah.onConnected(com.google.android.gms:play-services-base@@18.4.0:1) at com.google.android.gms.common.internal.zzf.zzd(com.google.android.gms:play-services-basement@@18.3.0:10) at com.google.android.gms.common.internal.zza.zza(com.google.android.gms:play-services-basement@@18.3.0:1) at com.google.android.gms.common.internal.zzc.zze(com.google.android.gms:play-services-basement@@18.3.0:3) at com.google.android.gms.common.internal.zzb.handleMessage(com.google.android.gms:play-services-basement@@18.3.0:31) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.os.HandlerThread.run(HandlerThread.java:68)

  2. Assistant

    It looks like your app is encountering a SecurityException with the message:

    ActivityTransitionRequest specified an unsupported transition activity type.
    

    This exception typically occurs when the ActivityTransitionRequest includes an activity type that is not supported or is invalid. Here's how you can troubleshoot and resolve this issue:

    1. Verify Supported Activity Types:

      Ensure that you're only using valid activity types defined in the DetectedActivity class when creating your ActivityTransitionRequest. The supported activity types for activity transitions are:

      • DetectedActivity.IN_VEHICLE
      • DetectedActivity.ON_BICYCLE
      • DetectedActivity.RUNNING
      • DetectedActivity.STILL
      • DetectedActivity.WALKING

      Note: As of the latest APIs, certain activity types like DetectedActivity.ON_FOOT, DetectedActivity.TILTING, and DetectedActivity.UNKNOWN are not supported for activity transitions and will cause this exception if used.

      Action: Check your code where you create ActivityTransition objects and ensure you're only using the supported activity types.

      ActivityTransition transition = new ActivityTransition.Builder()
              .setActivityType(DetectedActivity.WALKING)
              .setTransitionType(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
              .build();
      
    2. Check for Deprecated or Unsupported Activities:

      If you've used activities like DetectedActivity.ON_FOOT in your transition requests, replace them with supported ones. For example, if you want to detect when a user is on foot, consider requesting both DetectedActivity.WALKING and DetectedActivity.RUNNING.

    3. Ensure Proper Permissions:

      Starting from Android 10 (API level 29), the ACTIVITY_RECOGNITION permission is required.

      • In your AndroidManifest.xml, add:

        <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
        
      • For devices running Android 6.0 (API level 23) and above, request this permission at runtime:

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACTIVITY_RECOGNITION)
                != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.ACTIVITY_RECOGNITION},
                    REQUEST_CODE);
        }
        
    4. Update Google Play Services Dependency:

      Make sure you're using the latest version of the Google Play Services Location library in your build.gradle:

      implementation 'com.google.android.gms:play-services-location:21.0.1'
      

      Replace 21.0.1 with the latest version available.

    5. Handle the Exception Gracefully:

      Even after ensuring everything, it's good practice to handle potential exceptions when registering for transitions.

      try {
          ActivityRecognition.getClient(context)
                  .requestActivityTransitionUpdates(transitionRequest, getPendingIntent());
      } catch (SecurityException e) {
          // Handle exception
      }
      
    6. Debugging Steps:

      • Log Activity Types: Before creating the transition request, log the activity types you're using to ensure they're valid.

        Log.d("ActivityType", "Requesting transition for activity type: " + activityType);
        
      • Check Device Compatibility: Some devices or OS versions might have issues with certain activity types.

    7. Consult the Official Documentation:

      Refer to the Activity Recognition API documentation to ensure you're following the latest guidelines.

    Example Code Adjustment

    If your original code looked something like this (using an unsupported activity type):

    ActivityTransition transition = new ActivityTransition.Builder()
            .setActivityType(DetectedActivity.ON_FOOT) // Unsupported for transitions
            .setTransitionType(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
            .build();
    

    You should change it to:

    List<ActivityTransition> transitions = new ArrayList<>();
    
    transitions.add(new ActivityTransition.Builder()
            .setActivityType(DetectedActivity.WALKING)
            .setTransitionType(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
            .build());
    
    transitions.add(new ActivityTransition.Builder()
            .setActivityType(DetectedActivity.RUNNING)
            .setTransitionType(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
            .build());
    

    Using both WALKING and RUNNING to cover the ON_FOOT scenario.

    Summary

    • Use only supported activity types in ActivityTransitionRequest.
    • Ensure necessary permissions are declared and requested.
    • Update dependencies to the latest versions.
    • Handle exceptions to prevent crashes.
    • Refer to the official documentation and update your code accordingly.

    If you continue to face issues, please share the code snippet where you create the ActivityTransitionRequest, and I'll be happy to help you further.