mak12 / react-native-background-geolocation

Background and foreground geolocation plugin for React Native. Tracks user when app is running in background.
Apache License 2.0
8 stars 3 forks source link

com.google.android.gms.location.ActivityRecognitionResult.getProbableActivities()' on a nul #1

Closed LightKnight3r closed 1 year ago

LightKnight3r commented 1 year ago

ADB log: java.lang.RuntimeException: Error receiving broadcast Intent { act= com.marianhello.bgloc.DETECTED_ACTIVITY_UPDATE flg=0x10 } in com.marianhello.bgloc.provider.ActivityRecognitionLocationProvider$1@dfc5856 at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1815) at android.app.LoadedApk$ReceiverDispatcher$Args$$ExternalSyntheticLambda0.run(Unknown Source:2) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.os.HandlerThread.run(HandlerThread.java:67) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.google.android.gms.location.ActivityRecognitionResult.getProbableActivities()' on a null object reference at com.marianhello.bgloc.provider.ActivityRecognitionLocationProvider$1.onReceive(ActivityRecognitionLocationProvider.java:236) at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1805) at android.app.LoadedApk$ReceiverDispatcher$Args$$ExternalSyntheticLambda0.run(Unknown Source:2)  at android.os.Handler.handleCallback(Handler.java:938)  at android.os.Handler.dispatchMessage(Handler.java:99)  at android.os.Looper.loopOnce(Looper.java:226)  at android.os.Looper.loop(Looper.java:313)  at android.os.HandlerThread.run(HandlerThread.java:67) 

@mak12 i got this error make my app crash. it cause by "getProbableActivities()' on a null". can you fix it?

mak12 commented 1 year ago

Hi, @LightKnight3r can you share more logs? device android version and other info and if you have any more logs that would be great.

LightKnight3r commented 1 year ago

@mak12 thanks for reply. This error occurs when i use ACTIVITY_PROVIDER and listen location change in background. Whenever user's activity update, ActivityRecognitionLocationProvider will report changes. The function getProbableActivities() from ActivityRecognitionResult return null make app crash

mak12 commented 1 year ago

@LightKnight3r got it, will look into it today.

LightKnight3r commented 1 year ago

hi @mak12, i make a pull request to handle this issue. Can you check and release it? https://github.com/mak12/background-geolocation-android/pull/2

mak12 commented 1 year ago

yes sure will check this too, Have you tested this change? @LightKnight3r

LightKnight3r commented 1 year ago

yes, i think this error cause by changing new flag "FLAG_IMMUTABLE", sometimes ActivityRecognitionResult.extractResult has no result. I fixed by checking hasResult() condition. Maybe can use try - catch. https://stackoverflow.com/questions/70065929/getting-activityrecognitionresult-extractresultintent-as-null-while-trying-t

mak12 commented 1 year ago

@LightKnight3r yes that's what I had in my mind, and will try to fix this.

mak12 commented 1 year ago

@LightKnight3r Hi please upgrade library to newer version 0.7.7. This has some other fixes too.