The requirement is for an enterprise application. The application will be started on device boot. It will be running in the background and the user should not be able to disable or Stop the application. In Android a user can go to Settings->Application->Manage Application and stop my application. Is there any way to prevent this from happening?
No there is not. You can prevent Android from stopping the application by utilizing a Service and marking it as a foreground service, though this will require your application to display an icon in the status bar.
You can not make your application live forever, but it depends on what you really want to do. It's possible to receive a lot of events of the mobile and execute code even if your Activity/Service is not running. You can use BroadcastReceivers to look for interesting events and then start a service. I do it for an Enterprise Application that sends an event to a main server when the user has received/made a call.
Related
I'm developing app for enterprise which will be used in custom hardware setup without a display and Android 11. Now I'm debugging an app on a smartphone with a display (smartphone will be used as a platform in future but without a display). Android has a restriction (https://developer.android.com/guide/components/foreground-services#access-restrictions) for starting foreground services which are using camera or microphone in background, so I'm stuck here.
Is there any way to start this service without any user interaction? Maybe Device Policy Controller provides a way to remove this limitations?
Thank you.
P.S. App provides life safety features, user knows about filming and accepts it directly, also app informs user with text-to-speech announcement, so ethic side is ok here.
Is there any way to start this service without any user interaction? Maybe Device Policy Controller provides a way to remove this limitations?
Yes. You can start your foreground service without user interaction. You can schedule your foreground service to start at a certain time using AlarmManager or periodic time using WorkManager or start it remotely for example using FCM or even start it based on some events using BroadCastReceiver.
To start a foreground service in android O and above you must start showing a notification and specify foreground service types in manifest and at runtime. for example, in work manager, it will be like this.
To record video from foreground service, you can use Camera or Camera2 depending on your target android version. There is also CameraX which I did not use in the foreground service.
To start your app when startup you can use BOOT_COMPLETED broadCastReceiver. I hope this be helpful🙂.
I am trying to find how to enable the application to perform a background task.
I use the example seen here "http://saigeethamn.blogspot.fr/2009/09/android-developer-tutorial-part-9.html" and I do not know if that is how I have proceed to execute a script permanently?
Also how to get it reactivated when starting the mobile?
So how should we do and if we can so that the service works even if you force stopping the application?
A big thank you for your help
No service can work if the user force stops an application. Force stopping puts the entire app into a state where no services, receivers, or activities can be run unless the user explicitly does so.
If you want to start a service when the phone starts, you need a broadcast receiver for the BOOT_COMPLETE broadcast.
I have an android app which waits for incoming calls to arrive and then (when the call state changes (I'm using the telephony manager class to detect incoming calls and its working great)) my app does something.
The problem is, if my app is running and listening for calls in the background, and then I open some other heavy apps and using them massively, my app gets paused by the system and the user must re-open it in order to resume listening for phone calls.
Is there a way to keep my app waiting for calls as long as the user didn't press on the "stop listening" button inside my app ?
Thanks.
Maybe this wil help you ,i had the same thing and i solved it with this answer
Use Broadcast Receiver to receive telephony broadcasts, which you have to register in a background Service. This way, the system will automatically notify your app about the events and also restart the app if it's not already running (of course, it won't happen if the app was force closed).
I'm developing an application that uses a Bound Service to query information from a server and provide notifications when conditions are met. At the moment, the user must execute the application from their home screen in order to begin receiving updates. But, for example, applications like the Facebook Messenger and Llama run from the moment the phone starts in the background. How do I achieve similar functionality for my long-term application? Also, even when my application is run from the home screen, it will still ocationally quit in the background from what I assume to be the system quitting the application for additional resources. Even though my application is made to restore the service when it begins again, it never seems to restart after it quits (usually after 3 to 4 hours of background activity).
Thanks for your help.
You can register a BroadcastReceiver for the ACTION_BOOT_COMPLETED Intent to detect when the device is booted. This requires the RECEIVE_BOOT_COMPLETED permission.
Instead of using a bound Service you can use a started sticky Service. However, depending on what exactly you want to do, you might want to check if AlarmManager suits your requirements better (maybe in combination with an IntentService, cf. cwac-wakeful).
I wrote an bluetooth app with my bt-connection established in a service, so the connection is still alive when I minimize my app.
But when watching my task manager, my app is still there.
And when calling onDestroy in my app, I have to stop my Service.
But other apps like telegram or skype (whatsapp too I think) aren't in my task-manager visible but by having an incoming message they notify me nevertheless.
How is this even possible? How can I write my bluetooth connection like this, that I can really close my app and anyway the incoming messages will be handled?
The other apps might be having some light weight service running in other process which gets the data for the main app.Go to settings->application manager->running processes..you will see all the service..
Other mechanism which apps use is port-directed sms. In such a scenario you don't need any service running.However port directed sms doesnt work on all the phone and for all the apps.
When you put remove your application from the foreground, Android keeps the activity on the stack again in case you will go back to it (unless you explicitly destroy the activity). So this maybe one reason why you still see it in the Task Manager.
You cannot kill entirely the app and it will still post messages. Your service will be running in the background and it will be visible in the app Manager->Running Services.
However if you destroy your activities the app it will not be visible in the app list of the Task Manager.