B4A Library Physical Activity Recognition Detection

Status
Not open for further replies.
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:
B4X:
#AdditionalJar: com.google.android.gms:play-services-location
2. Add to manifest editor:
B4X:
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
    16.6 KB · Views: 357
Last edited:

brunnlechner

Member
Licensed User
Longtime User
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:

brunnlechner

Member
Licensed User
Longtime User

Attachments

  • activity recognition sample.png
    activity recognition sample.png
    87.8 KB · Views: 360

Rusty

Well-Known Member
Licensed User
Longtime User
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
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
 

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks Don,
I upgraded to V6, the day it was released. No happiness on this one.
any other ideas?
Rusty
 

Rusty

Well-Known Member
Licensed User
Longtime User
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)
Any advice on this?
Thanks,
Rusty
 

Rusty

Well-Known Member
Licensed User
Longtime User
...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
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.
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
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
Look THIS
 

brunnlechner

Member
Licensed User
Longtime User
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.

******************
Fixed bug: always ar.Initialize("ar") just before ar.Connect(5000)
******************
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.
 

trueboss323

Active Member
Licensed User
Longtime User
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:

Sgardy

Member
Licensed User
Longtime User
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
 
Status
Not open for further replies.
Top