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 May 12, 2016 #121 You can use the new #ExcludeClasses attribute to remove most of the classes: https://www.b4x.com/android/forum/posts/398974/ The resources don't add too much to the compiled APK. You can probably remove most of them (I haven't tried).
You can use the new #ExcludeClasses attribute to remove most of the classes: https://www.b4x.com/android/forum/posts/398974/ The resources don't add too much to the compiled APK. You can probably remove most of them (I haven't tried).
B brunnlechner Member Licensed User Longtime User May 20, 2016 #122 Hallo, the Activity Recognition Example works, but when I press stop and then start any more activities are displayed. Only when I finish in the task manager and start it works again. This Example, is an "improved" version of the Activity Recognition Example is works fine. Activity Recognition Example Version 1.0 njdude.activityrecognition.sample https://jumpshare.com/b/GLiDOG2y4aVjAigh1bz0 Thank you Franz Last edited: May 20, 2016
Hallo, the Activity Recognition Example works, but when I press stop and then start any more activities are displayed. Only when I finish in the task manager and start it works again. This Example, is an "improved" version of the Activity Recognition Example is works fine. Activity Recognition Example Version 1.0 njdude.activityrecognition.sample https://jumpshare.com/b/GLiDOG2y4aVjAigh1bz0 Thank you Franz
Erel B4X founder Staff member Licensed User Longtime User May 20, 2016 #123 What do you mean with press stop? Where?
B brunnlechner Member Licensed User Longtime User May 20, 2016 #124 Button Start: Activity is displayed Button Stop ( ar.Stop) : Activity is stopped Button Start (ar.Connect(5000)): not Activity is displayed https://www.b4x.com/android/forum/attachments/activityrecognition_sample-zip. Attachments activity recognition sample.png 87.8 KB · Views: 814
Button Start: Activity is displayed Button Stop ( ar.Stop) : Activity is stopped Button Start (ar.Connect(5000)): not Activity is displayed https://www.b4x.com/android/forum/attachments/activityrecognition_sample-zip.
Erel B4X founder Staff member Licensed User Longtime User May 22, 2016 #125 You should upload the project you are running.
Rusty Well-Known Member Licensed User Longtime User Sep 8, 2016 #126 I'm having problems getting the Google-Play-service_lib\res installed. When I bring up the SDK manager, it shows it is installed, but I keep getting this error: ERROR: resource directory 'c:\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\res' does not exist Click to expand... The path exists up to here: c:\android-sdk\extras\google\google_play_services And in fact, the file doesn't exist... I've tried to install it, but no luck. Ideas? Thanks, Rusty
I'm having problems getting the Google-Play-service_lib\res installed. When I bring up the SDK manager, it shows it is installed, but I keep getting this error: ERROR: resource directory 'c:\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\res' does not exist Click to expand... The path exists up to here: c:\android-sdk\extras\google\google_play_services And in fact, the file doesn't exist... I've tried to install it, but no luck. Ideas? Thanks, Rusty
DonManfred Expert Licensed User Longtime User Sep 8, 2016 #127 Rusty said: Ideas? Click to expand... Update B4A to V6+
Rusty Well-Known Member Licensed User Longtime User Sep 8, 2016 #128 Thanks Don, I upgraded to V6, the day it was released. No happiness on this one. any other ideas? Rusty
Thanks Don, I upgraded to V6, the day it was released. No happiness on this one. any other ideas? Rusty
Erel B4X founder Staff member Licensed User Longtime User Sep 8, 2016 #129 I've updated the first post. Please follow the updated instructions.
Rusty Well-Known Member Licensed User Longtime User Sep 8, 2016 #130 Thanks Erel, I'm surely doing something wrong. I completely un-installed the Android SDK, downloaded a new one and installed it specifically selecting Google Play Services to be installed. When I look at the C:\Android-SDK\extras\google\google_play_services folder, there is no .jar file at all. There are only: docs (folder) samples (Folder) source.properties (file) Click to expand... Any advice on this? Thanks, Rusty
Thanks Erel, I'm surely doing something wrong. I completely un-installed the Android SDK, downloaded a new one and installed it specifically selecting Google Play Services to be installed. When I look at the C:\Android-SDK\extras\google\google_play_services folder, there is no .jar file at all. There are only: docs (folder) samples (Folder) source.properties (file) Click to expand... Any advice on this? Thanks, Rusty
Erel B4X founder Staff member Licensed User Longtime User Sep 8, 2016 #131 The jar is no longer needed or available. You need to install the two repositories: https://www.b4x.com/android/forum/threads/67692/#content
The jar is no longer needed or available. You need to install the two repositories: https://www.b4x.com/android/forum/threads/67692/#content
Rusty Well-Known Member Licensed User Longtime User Sep 29, 2016 #132 ...re removed and re installed SDK. After MANY "install X packages", finally it installed required content as per your last post. Thanks
...re removed and re installed SDK. After MANY "install X packages", finally it installed required content as per your last post. Thanks
Sgardy Member Licensed User Longtime User Dec 14, 2016 #133 NJDude said: The attached sample uses this new library and displays the results on an activity, when the HOME key it pressed, the results will show on the status bar via a notification. There's room for improvement, but this code might give you an idea. Click to expand... I get this... why? Compiling generated Java code. Error B4A line: 45 ar.Initialize(\ javac 1.8.0_20 src\njdude\activityrecognition\sample\main.java:344: error: cannot access GooglePlayServicesClient _v5.Initialize("ar",processBA); ^ class file for com.google.android.gms.common.GooglePlayServicesClient not found
NJDude said: The attached sample uses this new library and displays the results on an activity, when the HOME key it pressed, the results will show on the status bar via a notification. There's room for improvement, but this code might give you an idea. Click to expand... I get this... why? Compiling generated Java code. Error B4A line: 45 ar.Initialize(\ javac 1.8.0_20 src\njdude\activityrecognition\sample\main.java:344: error: cannot access GooglePlayServicesClient _v5.Initialize("ar",processBA); ^ class file for com.google.android.gms.common.GooglePlayServicesClient not found
MarcoRome Expert Licensed User Longtime User Dec 14, 2016 #134 Sgardy said: I get this... why? Compiling generated Java code. Error B4A line: 45 ar.Initialize(\ javac 1.8.0_20 src\njdude\activityrecognition\sample\main.java:344: error: cannot access GooglePlayServicesClient _v5.Initialize("ar",processBA); ^ class file for com.google.android.gms.common.GooglePlayServicesClient not found Click to expand... Look THIS
Sgardy said: I get this... why? Compiling generated Java code. Error B4A line: 45 ar.Initialize(\ javac 1.8.0_20 src\njdude\activityrecognition\sample\main.java:344: error: cannot access GooglePlayServicesClient _v5.Initialize("ar",processBA); ^ class file for com.google.android.gms.common.GooglePlayServicesClient not found Click to expand... Look THIS
B brunnlechner Member Licensed User Longtime User Oct 6, 2017 #135 brunnlechner said: Button Start: Activity is displayed Button Stop ( ar.Stop) : Activity is stopped Button Start (ar.Connect(5000)): not Activity is displayed https://www.b4x.com/android/forum/attachments/activityrecognition_sample-zip. Click to expand... ****************** Fixed bug: always ar.Initialize("ar") just before ar.Connect(5000) ****************** brunnlechner said: Button Start: Activity is displayed Button Stop ( ar.Stop) : Activity is stopped Button Start (ar.Connect(5000)): not Activity is displayed https://www.b4x.com/android/forum/attachments/activityrecognition_sample-zip. Click to expand...
brunnlechner said: Button Start: Activity is displayed Button Stop ( ar.Stop) : Activity is stopped Button Start (ar.Connect(5000)): not Activity is displayed https://www.b4x.com/android/forum/attachments/activityrecognition_sample-zip. Click to expand... ****************** Fixed bug: always ar.Initialize("ar") just before ar.Connect(5000) ****************** brunnlechner said: Button Start: Activity is displayed Button Stop ( ar.Stop) : Activity is stopped Button Start (ar.Connect(5000)): not Activity is displayed https://www.b4x.com/android/forum/attachments/activityrecognition_sample-zip. Click to expand...
T trueboss323 Active Member Licensed User Longtime User Jul 29, 2018 #136 Does this library work properly while you are driving but stopped at a red light? Would it stay at in vehicle or change to on foot? Last edited: Jul 29, 2018
Does this library work properly while you are driving but stopped at a red light? Would it stay at in vehicle or change to on foot?
Erel B4X founder Staff member Licensed User Longtime User Jul 29, 2018 #137 You will need to test it...
Sgardy Member Licensed User Longtime User Jan 13, 2019 #138 Hi Erel, why do I get this? ar.Initialize(\ javac 1.8.0_20 src\b4a\example\main.java:344: error: cannot access GooglePlayServicesClient _v5.Initialize("ar",processBA); ^ class file for com.google.android.gms.common.GooglePlayServicesClient not found
Hi Erel, why do I get this? ar.Initialize(\ javac 1.8.0_20 src\b4a\example\main.java:344: error: cannot access GooglePlayServicesClient _v5.Initialize("ar",processBA); ^ class file for com.google.android.gms.common.GooglePlayServicesClient not found
Erel B4X founder Staff member Licensed User Longtime User Jan 14, 2019 #139 Please start a new thread and upload your project.
Erel B4X founder Staff member Licensed User Longtime User May 27, 2020 #140 V3.00 - Completely new version, released as a class instead of a library. It is based on a new Google API. Not backward compatible.
V3.00 - Completely new version, released as a class instead of a library. It is based on a new Google API. Not backward compatible.