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.
NJDude Expert Licensed User Longtime User Jul 10, 2014 #41 I have tested this code on 4.4.2. 4.4.4 and 4.0.3 and works fine.
G grafsoft Well-Known Member Licensed User Longtime User Jul 10, 2014 #42 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)
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 Jul 10, 2014 #43 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 ?
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 ?
NJDude Expert Licensed User Longtime User Jul 10, 2014 #44 Have you guys tried the sample I posted on this thread? same results?
brelto85 Active Member Licensed User Longtime User Jul 10, 2014 #45 yes, i tried with ActivityRecognition_Sample project
NJDude Expert Licensed User Longtime User Jul 10, 2014 #46 That's interesting, I don't have any issues, and I also tried on a HTC One (m7), no issues at all.
Erel B4X founder Staff member Licensed User Longtime User Jul 11, 2014 #47 @grafsoft are you using B4A v3.82?
brelto85 Active Member Licensed User Longtime User Jul 11, 2014 #48 @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 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 Jul 12, 2014 #50 brelto85 said: any suggestion? Click to expand... 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 said: any suggestion? Click to expand... 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 Jul 12, 2014 #51 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
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 Jul 12, 2014 #52 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.
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.
brelto85 Active Member Licensed User Longtime User Jul 12, 2014 #53 ok, what is your reference into Configuration Paths of B4A IDE?
NJDude Expert Licensed User Longtime User Jul 12, 2014 #54 These are my B4A Settings, and my SDK. Last edited: Jul 14, 2014
GMan Well-Known Member Licensed User Longtime User Jul 12, 2014 #55 Same as mine...but still not working
brelto85 Active Member Licensed User Longtime User Jul 14, 2014 #56 GMan said: Same as mine...but still not working Click to expand... i'm not the only one that have this problem.. What is the difference between "Android L (API 20)" and "Android 4.4W (API 20)" ? I've installed the Android L version
GMan said: Same as mine...but still not working Click to expand... i'm not the only one that have this problem.. What is the difference between "Android L (API 20)" and "Android 4.4W (API 20)" ? I've installed the Android L version
GMan Well-Known Member Licensed User Longtime User Jul 14, 2014 #57 See here a quick overview (visually): http://www.androidbeat.com/2014/06/android-kitkat-vs-android-l-visual-comparison/
See here a quick overview (visually): http://www.androidbeat.com/2014/06/android-kitkat-vs-android-l-visual-comparison/
NJDude Expert Licensed User Longtime User Jul 14, 2014 #58 brelto85 said: i'm not the only one that have this problem.. What is the difference between "Android L (API 20)" and "Android 4.4W (API 20)" ? I've installed the Android L version Click to expand... Android L (API 20) is a "preview" version, Android 4.4W is the "wear" version.
brelto85 said: i'm not the only one that have this problem.. What is the difference between "Android L (API 20)" and "Android 4.4W (API 20)" ? I've installed the Android L version Click to expand... Android L (API 20) is a "preview" version, Android 4.4W is the "wear" version.
brelto85 Active Member Licensed User Longtime User Jul 14, 2014 #59 ok thanks The javac.exe file could be interested to this library? my jdk version is 1.7.x
Erel B4X founder Staff member Licensed User Longtime User Jul 15, 2014 #60 No. It will work with Java 6 and above. Note that only B4A v3.82(+) supports Google Play Services v18.
No. It will work with Java 6 and above. Note that only B4A v3.82(+) supports Google Play Services v18.