I am trying to create a locker application to show pin view when the user enters to defended application. I created a service that runs and tracks the current foreground application. However, on devices with android version 10 activity is not starting from my service. I know that from android 10 there are restrictions to start an activity from the background, however, there are exceptions either. The activity can start from the background when the application is in the foreground, but it won't help in my case. So the question is how can I start the activity from service to show pin view?
P.s: I tried it with window manager but again in higher android versions there is an annoying notification that can open settings do dismiss overlay permission. Also, I saw a working "app locker" application in the play store, so I believe there is a way.
From android 10 foreground service will work only if u start the service while the app is in foreground. If your app is in background you will need background location permission which has to be requested separate after you gain permission for coarse and fine location. Also if your app is in testing mode and not in Play Store and u update your device to android 10 a fresh install of the app is needed.
There is no point in using a foreground service if u want to start that service from background. Just get background location and stop using foreground service.
Related
When I used foreground service then when I kill the application then foreground service is automatically killed but I want to alive foreground service when the application is killed. this issue appeared in android 10 and android 11. how to solve this issue.
You can't do that as you should not be able to keep alive a foreground service after the application is killed.
You should only use a foreground service when your app needs to perform a task that is noticeable by the user even when they're not directly interacting with the app. If the action is of low enough importance that you want to use a minimum-priority notification, create a background task instead.
If you what to have some background service working, that will be possible.
You can find some useful information here :
https://developer.android.com/guide/components/foreground-services
https://developer.android.com/training/run-background-service/create-service
It should not get killed. When starting foreground service you need to create notification too. You have done that, right?
If you done everything right there is possibility that you have xiaomi phone. Xiaomi deletes everything when app killed. You need to add specific intent protection...
I create background and foreground service both to get android location on every Interval and send it to server.
When App is in foreground at that time service run fine but when app is in background my foreground service notification display perfect for few minutes after some time it automatically killed my service and I am not getting any location update after that.
It runs fine in Samsung device but create issue in Oppo,Vivo, Mi and OnePlus device
So please help me out to find best way to run Location service when app is closed, background or foreground in any state in all device and Android version greater Than "O"
Thanks in Advance
I am developing a custom dailer App incoming call screen but my problem is that when the app is in foreground, on incoming call the broadcast receiver is called and displays the custom screen but when the app is in the background or not in running state then the broadcast receiver is not called.
How to resolve this?
And Also Getting this Log
ConnectionTracker: Exception thrown while unbinding
java.lang.IllegalArgumentException: Service not registered: lt#3e5af9d
On some devices (notably low-end and Chinese manufacture) apps are not permitted to perform background activities if they are not in a list of "protected apps". This is done to save battery life. If your device does this, it will not launch a BroadcastReceiver if the app is not already running. To fix this you will need to manually add your app to the list of "protected apps" or "apps allowed to perform background activities". There is a setting in the Android settings for the user to maintain this list of apps. It is usually in the "Security" or "Power management" settings somewhere.
I am working on an Android fall detection application. When user falls, alarm with timer turns on and if user not clik cancel within 15s, app send SMS to contact. Everything works fine when app is open but I don't know how my foreground service should work. Is it possible to make foreground service work like that- after fall detected foreground service open application and run timer from Main Activity?
Code from foreground service opening MainActivity:
Intent myIntent= new Intent(this, MainActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myIntent);
There are two obstacles to your use case:
Firstly, starting from Android 10, there are new restrictions on starting an activity when your app is in the background (and as it's written on the android developer page, even with a foreground service, your app will be considered in the background if no activities are in foreground). So you won't be able to "pop" a view to the user, except if you target a version < 29 (but it's not very recommended).
Secondly, since the beginning of 2019, the Google Play Developer Policy has been updated and you cannot use anymore the SEND_SMS permission, unless if you can justify in the publish console that your app is an SMS handler and you will need the user to register it as the default one. So you won't be able to send an automatic text message directly.
You can try to change the notification message to alert the user and try to have him click on the notification to open an activity.
Issue : Activity recognition API has an intent service which will get the motion activities and will get as part of intent (onHandleIntent). When I changed my app to target android Oreo, the functionality behaves as below
While app is in foreground, app detects activities.
while app in background, it doesn't detect activities
I tried to change the intent service to JobIntentService but not working.
Can anyone help on this?
Thanks in advance.
I faced the same issue. My app worked like charm on previous versions of Android, but no location updates in Oreo.
Found the solution in:
https://developer.android.com/about/versions/oreo/background-location-limits.html
I have a service as location listener that runs in the background. In orea background services get only few location updates. It has to be changed to a foreground service.
The only thing I had to do is calling startForeground() within onCreate() of the service.
You should check for location retreiving limitations for apps on Oreo when in background or using background services. The answer is to use foreground service or bring app to foreground.