Reputation: 371
I'm running the Google Codelab Android Activity Recognition API example on my Samsung 8+ https://codelabs.developers.google.com/codelabs/activity-recognition-transition/
And although the example starts fine on my phone, I do not get any events from the activity recognition API. I first though that it might be a permission issue, but On Android 9 I could not find a permission setting for the ACTIVITY_RECOGNITION, this seems to be necessary for Android 10 onwards.
Could someone give a pointer what possible reasons might be that my Samsung 8+ is not getting any Activity Recognition events?
Upvotes: 3
Views: 785
Reputation: 97
Even registering broadcast receiver in Manifest file,you need to register in dynamically in Oreo+ otherwise it will not work. Try this.Add this code in main activity or in startCommand in Service.It worked for me.I have tested this code on Android 10 too..worked perfectly.You dont need to register broadcast receiver in Manifest.
@Override
protected void onStart() {
super.onStart();
IntentFilter intentFilter=new IntentFilter(Constants.BROADCAST_DETECTED_ACTIVITY);
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
registerReceiver(broadcastReceiver,intentFilter);
}
Upvotes: 1
Reputation: 43
I have 2 Xiaomi phone that is running Android 9. 1 is Redmi Note 3 and is working . The other 1 is Pocophone and it is not working.
Then I tested with Samsung Galaxy Grand Prime Android 5. It is working. Now I am confused why some device it appears but some not appear.
Upvotes: 2