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?
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.
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);
}
Related
I'm starting to develop for android, and I'm having an issue about services. I did a lot of research about this, but couldn't find a solution.
I'm doing an app that collects RFID tags information. For that, I'm using a third-party middleware that handles the bluetooth connection to the RFID reader and other events (like connecting, reading, errors etc). So, my app creates a broadcast receiver that handles all the message and data intents sent by the middleware. For this part, everything's fine.
The problem is that I'm trying to start middleware service using the code below (provided by the middleware documentation), but it doesn't work.
Intent intent = new Intent("com.supplier.middleware.runner");
intent.setPackage("com.supplier.middleware");
startService(intent);
I'm currently using an Asus Zenfone MAX M1 (ASUS_X00HD) with Android 8.1.0. The documentation also describes a way to stop the service (which I must use when I close the app), and the stop service intent works. So, if I start the middleware manually and try to close programatically, it works fine.
After some days trying - unsuccessfully - to solve this, I tested my app with a Motorola Moto Maxx (which is Android 6, I think) and with a Samsung J1 (which is Android 5.1.1) and both smartphones worked fine: when I call the startService, a notification item appears; when I call stopService, the notification item goes away.
I also tried to use "startForegroundService" because of the Android 8, but no success either.
Is there a way to "monitor" the startService calls, so maybe I could track any error? Am I doing something wrong - or rather, am I not doing something that is important?
In Android 8.0 background service limitation.
https://developer.android.com/about/versions/oreo/background.html
You can use JobIntentService instead of intent service. It can work.
I'm here developed a hybrid cordova based android app in which i need to do some task before killing app for this i wrote below code onDestroy() in MainActivity and onTaskRemoved in one of service class which is calling perfectly on Samsum, Motorola, Asus etc. many device except Redmi MI Devices.
Some days back the same code was working in MI device but now its not after updating MI with MIUI 9.6.0 and above. I have tested one of MI device with MI 9.5.0 in which its working both the method but after upgrade of my device now its not working.
So is someone having the same issue? what we can do to achieve app killing event? is there any option through which it should start working or having any other way to do the same only for MI device?
I have checked over the internet and did changes for Autostart options as well still not working.
#Override
public void onTaskRemoved(Intent rootIntent) {
Log.d(getClass().getName(), "App just got removed from Recents!");
Toast.makeText(getApplicationContext(),"18. onTaskRemoved()", Toast.LENGTH_SHORT).show();
}
#Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(getApplicationContext(),"16. onDestroy()", Toast.LENGTH_SHORT).show();
}
Few OEMs including (RedMi) customizes the stack ROM for battery/memory optimization and have blocked the "onDestroy()" and "onTaskRemoved" callbacks.
As an user you can prevent the App's service from killing by locking the App.
Or, White listing the app by enabling "Autostart" setting for the App. Programmatically you can prompt the user to enable the Autostart for the App: Please find details here
Please note: I have tested the Autostart enabling programatically on few devices but found that it does not works always. So not sure how to fix in a proper way, but this solution might worked at-least up-to certain extent.
I've noticed in Google Play Console crashes that I get ClassCastException when casting to a CustomApplication in a Service or BroadcastReceiver:
((CustomApplication) getApplication()).getDiComponent().inject(this);
The name is set in manifest:
<application
android:name=".CustomApplication"
I also tried using getApplicationContext() but got same result:
((CustomApplication) getApplicationContext()).getDiComponent().inject(this);
This code is used in onCreate() method of a Service or onReceive of a broadcast receiver.
I cannot reproduce this crash but I have quite a lot looking at numbers. Any idea why it happens and how I could fix it?
UPDATES
OS affected: from 6.0 and up
Devices: mostly ZTE phones, 70%, but some Samsung also
My application contains a BOOT_COMPLETED receiver like described in other threads here. It works perfectly until I changed my app into a system application. Now the Receiver does not trigger the event anymore.
Any ideas for this issue? I'm using Android Kitkat 4.4.2 on a Radxa Rock Pro. Compiled my own image to register the app as system application.
we need more detail to help you, post the code and the manifest, also debug log, in other hand you must use Log.i(TAG, "onReceive."); to know if the problem is in onReceive() or when trying to run the service class.
I have written an SMS app to receive SMSes using the various samples available online. I tested it in a Android 2.3 device and it was working perfectly.
Now, I changed the API level to Android 4.0 and tried running it on an Android 4.0 device and nothing happens. I checked the logcat in Eclipse and nothing is displayed there too.
Any idea what needs to be done for it to work?
Check Once Again that you are actually creating and registering the
broadcast receiver in an Activity otherwise it will not get called
as after Android 3.1 it requires apps to be in started state to
receive broadcasts.