I had a few problems with my alarm that are in a another thread here if anyone could help but anyway here is a new question. If I set an alarm using my app, say for 5 minutes from now, and then close the app, how would I code it so that my app activity comes back to the front?
This is basically the same as the clock app already on most android phones. I'm doing this to allow the user to stop the alarm. Would I be right in saying that I would have to modify my existing code to, when the alarm is run, launch a new intent to bring the activity to the front? Or can I simplify this and only have an alertdialog or something open instead of opening the entire app?
Any links would be appreciated
Thanks
Don't move your activity to the front automatically. It's as annoying as a pop-up ad! Do you really want to try to interrupt the user who's trying to look up a phone number?
Instead, use a Service. When you want to tell the user something, post a status bar notification. You can set up the notification to bring up an Activity when the notification is clicked.
Most alarms are implemented in a Service.
Have you looked into the AlarmManager? http://developer.android.com/reference/android/app/AlarmManager.html. I've used it in the future to fire Intents for Notifications. The Notification can then open an Activity for the user when they select the Notification from the Android Notification Bar.
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'd like to know if it is possible to create a notification or toast/alert from my app when another app is opened. For example, my app Foo will create a notification if Facebook is opened.
Edit: What I actually want is to inform the user that my app is running in the background when the default camera app opens/running. My app will modify photos taken with the default camera app when it is running in the background and I want to inform the user that it will do so. Is this possible?
Basically what you want is a push notification. Please go through following tuts to help yourself:
https://neurobin.org/docs/android/push-notification-gcm-client-server/
https://developers.google.com/cloud-messaging/android/start
Yeah, you can take a look at this and then schedule an alarm using some background running process that looks for Facebook being running.
One way is to use AlarmManager to check running apps every 5-10 mins and you can generate a notification if your condition is met.
I have an app that starts when the phone starts. In the app I have an option for the user to stop showing a notification from the app. The notification is related to the boot_complete action (it starts a service). I'm wondering how would I stop the App from starting on boot up if the notification is turn off? I'm thinking on setting a shared preference to "No" if the notification is turned off and then check that on the boot complete broadcast. If the preference is set to "No", then nothing will start if it's set to "Yes" then it will start. Is that the best way of doing it or is there a better way to do it?
Yes this is the best way to do this, just implement it in your BroadcastReceiver. I have implemented this multiple times in my apps, it seems to work well.
I have developed an alert reminder type application, so when alarm is called my broadcast receiver call one activity and fire one notification and also start one service, it working good,
But when I working in other application some time the my service and notification is fired but activity is not open. it happen sometime not all.
So, how can I give the priority to my activity so it can open always if we working on other application, just like in call receiver screen.
I think you cannot bring your app to top when other other apps are in front. The call receiver screen is system window which has special privileges. You cannot have the same for your app.
As a alternative you can fire a notification to status bar.
I m a newbie to android development and i wanna know a right way to get notification as an activity instead of statusbar notification.
To be clear, i wanna display an notification on screen instead of adding it to status bar.
In that case you shouldn't call it notification. In Android, a notification is something that ends up in the status bar and that the user can deal with at her own leisure.
An activity will take over the complete screen and force the user to deal with it immediately. That is very intrusive and users will likely get annoyed, unless the information you show is really crucial.
The correct behaviour is to post a notification and bring up your activity when the user clicks on the notification, very much like your messaging client or email client.
Other options are bringing up a dialogue or a toaster message. A dialogue is a message the user will have to interact with to go away, whereas a toaster message will be visible for a short time and then automatically disappear.
Maybe you could be a bit more specific about what sort of information you want to provide to the user?
Surely you can be helped out.
I feel that you are getting notifications from a web service as a response to some request, right?
If yes, then you can display them in a custom made dialog box, or inside an activity whose theme has been set as DIALOG.
maybe I got your question wrong, maybe your talking about the notifications about networks, calls and things.
If its so, correct me.
Thanks!
Android 2.3 introduced a new field on Notification, fullScreenIntent, for exactly this purpose. Place a PendingIntent here that will trigger whatever activity you'd like to display, and the user will be sent to that activity (whether full-screen or dialog-themed) in addition to receiving the usual notification icon in the status bar. As of Gingerbread, this is how the Phone app implements the incoming call screen.