Jul 1, 2014 Replies: 140 Class updated on May 2023. This class allows you to monitor the user / device physical state (walking, running, still, etc.). The state detection is based on Android location services which use low power sensors to try to detect the current activity. Once you connect your app to these services you will receive notifications even when your app is in the background (similar to static intent filters). Configuration steps: 1. Add this line to the main activity: Code: #AdditionalJar: com.google.android.gms:play-services-location 2. Add to manifest editor: Code: CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase) AddPermission(com.google.android.gms.permission.ACTIVITY_RECOGNITION) AddPermission(android.permission.ACTIVITY_RECOGNITION) 3. Add a receiver named RecognitionReceiver that handles the events. See the attached example. Notes - Android may kill the process and then recreate it when a notification is delivered. This means that it is better to run the app in Release mode. Otherwise it will fail when the process is recreated. History V4.00 - Based on receiver instead of service. V3.00 - Released as a class instead of a library. It is based on a new Google API. Not backward compatible. Attachments ActivityRecognition.zip ActivityRecognition.zip 16.6 KB · Views: 951 Last edited: Jan 9, 2023 Click to expand...
Class updated on May 2023. This class allows you to monitor the user / device physical state (walking, running, still, etc.). The state detection is based on Android location services which use low power sensors to try to detect the current activity. Once you connect your app to these services you will receive notifications even when your app is in the background (similar to static intent filters). Configuration steps: 1. Add this line to the main activity: Code: #AdditionalJar: com.google.android.gms:play-services-location 2. Add to manifest editor: Code: CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase) AddPermission(com.google.android.gms.permission.ACTIVITY_RECOGNITION) AddPermission(android.permission.ACTIVITY_RECOGNITION) 3. Add a receiver named RecognitionReceiver that handles the events. See the attached example. Notes - Android may kill the process and then recreate it when a notification is delivered. This means that it is better to run the app in Release mode. Otherwise it will fail when the process is recreated. History V4.00 - Based on receiver instead of service. V3.00 - Released as a class instead of a library. It is based on a new Google API. Not backward compatible.
Erel B4X founder Staff member Licensed User Longtime User Jan 9, 2023 #141 New version released. It uses a receiver instead of service. Solution based on services will not work on new versions of Android. Requires B4A v12.2+ which wasn't yet released at this time.
New version released. It uses a receiver instead of service. Solution based on services will not work on new versions of Android. Requires B4A v12.2+ which wasn't yet released at this time.