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: 375
Last edited:

grafsoft

Well-Known Member
Licensed User
Longtime User
This is the error message:

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=Move.Ass/.main }
no extras
java.lang.ClassNotFoundException: anywheresoftware$b4a$objects$ActivityRecognition
at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:544)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:516)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:320)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at Move.Ass.main.afterFirstLayout(main.java:91)
at Move.Ass.main.access$100(main.java:16)
at Move.Ass.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
 

brelto85

Active Member
Licensed User
Longtime User
i've the HTC ONE s (OS 4.1.1) and the test project attached in this thread does not work
After click on Start button, is logged "Connected: true" but if i go walking, the service don't start

someone can help ?
 

brelto85

Active Member
Licensed User
Longtime User
@NJDude i don't know, also the old library LocationAPI (that i think that use the same android api) doesn't works
I updated the android sdk manager libraries with the last version
 

NJDude

Expert
Licensed User
Longtime User
any suggestion?
It has to be your setup, I have B4A 3.82, the latest SDK and Google Services, and my sample works on any version of Android above HoneyComb, I tested it on my Galaxy tab which has ICS, my Nexus 7 running KitKat 4.4.4 and my HTC One running 4.4.2, my suggestion would be, make sure you have the latest of everything, other than that, I don't know what else to say.
 

brelto85

Active Member
Licensed User
Longtime User
i've these version and packages installed in my pc:

- 3.82 B4A
- 23.0.2 android sdk tool
- 20 platform tools
- 20 sdk build tools
- Android L, 4.4.2, 4.3 packages
- ActivityRecognition 1.0 library
- In B4A library folder i've the google-play-services.jar copied from "C:\Program Files (x86)\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\libs"
- In the B4A Configuration Paths i've the "C:\Program Files (x86)\Android\android-sdk\platforms\android-19\android.jar" reference

the strange behavior is that after the last updates, also the LocationAPI project doesn't works
 

NJDude

Expert
Licensed User
Longtime User
Those are pretty much the same settings I have, the only difference is that I only have "android-20" instead of 19. At this point, I would say there's something on the build version on your device.
 

GMan

Well-Known Member
Licensed User
Longtime User
Same as mine...but still not working
 
Status
Not open for further replies.
Top