android / codelab-activity_transitionapi

Codelab walks you through tracking activity transition changes (start/stop run, walk, idle, drive, etc.).
Other
25 stars 11 forks source link

Application terminated or no activity reported on Android 13 #29

Open rapa4362 opened 1 year ago

rapa4362 commented 1 year ago

I did no changes in the code, compiled, ran on Samsung with Android 13, application was terminated with following error, adding FLAG_IMMUTABLE to PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0) eliminates the exception, but no activity is reported

FATAL EXCEPTION: main Process: com.google.example.android.basicactivityrecognitiontransitionsample, PID: 21094 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.example.android.basicactivityrecognitiontransitionsample/com.google.example.android.basicactivityrecognitiontransitionsample.MainActivity}: java.lang.IllegalArgumentException: com.google.example.android.basicactivityrecognitiontransitionsample: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.

sathvik87 commented 1 year ago

+1 . This can be solved by adding PendingIntent.FLAG_UPDATE_CURRENT| PendingIntent.FLAG_MUTABLE as last parameter while creating pendingIntent

binhbk230 commented 1 year ago

@sathvik87 I try it but it still not work, in android 13 it only detect STILL and WALKING activity, other activity not working. Do you have other solution? @rapa4362 Did you resolve it?