Is it possible to launch a service whenever a phone is booted up?
My question is that, say, I want to have a background service running in the background when the phone is booted up, once it receives a notification, say, a stock price is now above a certain price, then the user will get notified and in the notification center it will launch the actual app if a user chooses to click on it.
My question is, where do I put the tag? In my application manifest? but again, I only want the service to run automatically without user launching my app.
I see here two possibilities for you:
Is the same approach that was proposed by #triad. You can have a broadcast receiver that will start your service.
You can use push notifications. As I understand from the question it is possible in your case. I guess using push notifications will be cheaper (in the context of power) in your case.
Related
I have a food ordering app and I need to inform the restaurants of a new order. I have a Capacitor app which often runs in the background of tablets/phones of the restaurant. As a result, they sometimes miss an order.
In order to solve this, it would be great if I could ring the device as if an alarm goes off or if the device gets a call. Then they can swipe away the notification to stop it or something like that, to make sure they saw it. I would choose the sound myself so that it isn't obnoxious.
Is anything like that possible?
yes it's possible but,
you should know the following:
for Android:
1-create a foreground service to keep notification appears to the
restaurants, in this case the restaurant can not hide the
notification.
once the restaurant receive the notification just
sent an event to the foreground service to handle the action and the
data.
start the order activity from foreground service, once the
activity is created just play a sound.
for IOS,
it should be the same but i don't know how to create a foreground service in IOS.
I have the next doubt:
I am working on an app that needs to start a foreground service. I know that since Android O, you need to attach a notification to that foreground service. So far so good.
The question is: what happens if the user disables that notification from settings? I have been testing the app and everything seems to work, but I wanted to double check on internet and I couldn't find anything.
Should I force the user to have notifications enabled if he/she wants that feature (which needs the foreground service)?
Does anyone have some insights on it?
Yes, it is best practice to ask the user to enable notification services.
Nowadays most app does this exercise to show a notification to users. Even in some special manufacturer like MIUI it is compulsory to start notification service from setting. So many app shows prompt for same and on positive click they navigate the user to setting screen too
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).
Could someone please help me figurate how to make an app that has no icon and starts at the startup?
I want it to start in every startup and keep running all the time, because I want to Toast the name of the sender each time there's an incoming SMS.
I'm not sure what you mean by "hidden" as the O/S generally tries to avoid allowing you to hide behavior from the user. What you want to do is discussed in this question Trying to start a service on boot on Android. That will enable you to launch a service and then by watching for the appropriate intents related to SMS messages you can create the toasts you desire.
This requirement is only satisfied if the app is running in the background.And if the Screen is turned on if the user presses to check any notifications then an Asynctask is called if the app is running in the background and makes a call to the server.
I have tried using Broadcast Receiver when screen on and tried to execute, it works only if the app is on the front screen after pressing the home button .And then if the user presses Power button after an hour then nothing happens .
Basically I am not sure if the app is being killed after sometime when in background. Please help me.I am a noob in Android and this functionality is something I thought most of the developers might be using but I did not see anything except service calls and I really did not want any service/alarm-manager as I don't want it to work continuously.
TIA
how to make server call whenever device screen is turned ON without Service
This is not possible. ACTION_SCREEN_ON is a broadcast that can only be received by a BroadcastReceiver registered via registerReceiver(). So, unless you are the foreground activity, the only way you can receive this broadcast is via an always-running service, which is not a good idea.
as I don't want it to work continuously
Then do not "make server call whenever device screen is turned ON". Find some other solution for whatever business problem you have that you are trying to solve this way.