Android Question Problem with Activity Recognition Permission

Hi. I have a problem with the activity recognition permission. Because it is necessary to use the application. But if the user manually deactivates it from application permissions, I cannot find a way to verify that it is inactive and request that it be activated.

I need something like

Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
Wait For Activity_PermissionResult (permission As String, Result1 As Boolean)

But it didn't exists for activity recognition permission (or maybe the android permission is called physical activity)


__________________________________

I found this JAVA code, but i don't know how to implement it to B4A

The app should check if the permission is granted already:

if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.ACTIVITY_RECOGNITION)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
}
To request the permission:

ActivityCompat.requestPermissions(thisActivity,
arrayOf(Manifest.permission.ACTIVITY_RECOGNITION),
MY_PERMISSIONS_REQUEST_ACTIVITY_RECOGNITION);


Thank you for your help!
 
Hi erel, thank you for your help.

The problem is that i have to implement targetSdKVersion to 29 because of this change:


There is a new requirement in Android 10+ devices.
In order for the location tracking to continue working in the background, if the user chooses the "allow while app is open" permission option we need to add this line to the manifest editor:
B4X:

SetServiceAttribute(Tracker, android:foregroundServiceType, "location")

It also requires installing "android sdk platform 29" with B4A Sdk Manager and configuring the path to android.jar under Tools - Configure Paths to android.jar from platform 29.

It is another way? thank you
 
Upvote 0
I check and i actually have the android:targetSdkVersion="28". So that is not the problem.

I will search for another way to ask the user to activate like this (is for another app)
WhatsApp Image 2020-04-30 at 11.09.54.jpeg
 
Upvote 0
Hi. I was testing this. And even if you have targetSdkVersion = "28", when installing the app on an Android 10 device, Activity Recognition permission (Or physical activity Recognition, I'm not sure of the name). In other words, if the user does not manually enable use from application permissions, the user cannot use the API if it is not manually activated.

I attach an example with permission automatically denied

This is my Manifiest:
Android Manifiest:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)

CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)

AddApplicationText(<service
    android:name="anywheresoftware.b4a.objects.ActivityRecognition$RecognitionService">
   </service>
  )
 
AddApplicationText(
   <activity android:name="com.google.android.gms.common.api.GoogleApiActivity"
  android:theme="@android:style/Theme.Translucent.NoTitleBar"
  android:exported="false"/> 
<meta-data
    android:name="com.google.android.gms.version"
    android:value="[USER=21225]@Integer[/USER]/google_play_services_version" /> 
)

Sorry about my bad english, and thank you Erel for all your help!
 

Attachments

  • WhatsApp Image 2020-05-03 at 22.28.50.jpeg
    WhatsApp Image 2020-05-03 at 22.28.50.jpeg
    136.4 KB · Views: 225
Upvote 0
Top