I was wondering if there is a way to programatically set the phone's indicator icons, like GPS or upload/download in progress,etc.. ?
You have to use a Notification. Set the icon when initializing Notification class. You can get more details here
http://developer.android.com/guide/topics/ui/notifiers/notifications.html
Yes, Notifications is what you are looking for. If you are notifying the user about something that just happened (for instance, a message arrived), you should use a plain Notification 1. However, if you want to notify the user that a service is running, then you should call startForeground() from your Service 2, and stopForeground() when you are done with the operation.
Some points to keep an eye out for:
Only use notification for things the user cares about. This may seem pretty obvious, but you'll find a surprising number of applications that notify the user of some background maintenance process that they don't really care (or can do anything) about.
Let the user customize what sort of things should trigger a notification. It might be very annoying for the user if the phone is constantly beeping and vibrating.
Every notification should have an appropriate Intent that allows the user to take action on that particular notification, and that Intent should be the one that makes the most sense for that particular event -- for example, when the user taps a "new message" notification, he expects to be let to a screen where he can read the message. Sending the user to your application's home screen in that case will be much less useful.
Related
I've read a lot about notifications in iOS now and I'm quite confused about how to reliably schedule notifications, actually. Let me explain my scenario:
I created an Android app that holds a fixed list of dates. The user can not add or remove dates, he can only view that list (garbage removal dates for my area). You can, however, configure that you want to be notified the day before. I've made that app so that when the device starts, a notification timer is started that fires at a certain time, checks whether there are pending items for the next day and if so, shows a notification. Then it re-schedules itself for the next day. So normally, the user doesn't need to open the app at all to receive notifications. He only opens the app once to configure his street, which triggers the first scheduled event, or to actually see the list of upcoming dates.
I'm now trying to port this app to iOS and I understand from what I've read that there's no way to replicate the way I'm doing stuff on Android. I understand that I can create up to 64 notifications for certain points of time in advance, but without the user opening the app at all I can not be sure to reliably schedule all the notifications I may need.
Is there a reliable way to simulate the described Android behavior? Or is there a way to force the user to open up the app once every 30 days or so?
In a nutshell no.
If applicable you can make notifications repeating, but if the dates are random and you can't repeat the notification then you can't schedule more than the limit.
You can't schedule your app to run and you can't force the user to do anything. All you can do is post some sort of notification for 30 days or whenever with some message that you hope will compel them to open your app.
If you have a valid use case for it in your app, you can enable a background mode such as a location change on a cell tower transition for example, then when your app runs in the background re-schedule the notifications. Or remote push, or background fetch etc. But even with background modes you cannot guarantee your app will actually run in the background, you can just help to increase the chances that it might and the different background modes have different degrees of usefulness in this sort of area.
i want to pop-up a dialog while some specific event occurs. Say i am an antivirus and found a virus, i can't send notification for this right, user could be compromised even dead until he checks the notification.
So i want to show a dialog like allow-deny, or yes-no, not to disturb user, it's gonna happen very rarely.
So is there any way that a service or application shows a dialog while user is using another application, even playing a game.
Thanks in advance...
Have a look at the Notification documentation. I don't believe you can/should create an AlertDialog when its not in the foreground. See here for Android's information on design patterns regarding when you should and shouldn't use them (you're interested in the last paragraph.
To quote the documentation.
Dialogs and toasts are for feedback not notification
Your app should not create a dialog or toast if it is not currently on screen. Dialogs and Toasts should only be displayed as the immediate response to the user taking an action inside of your app. For further guidance on the use of dialogs and toasts, refer to Confirming & Acknowledging.
This is a better, less intrusive way of notifying the user in your specific case. I also know that its possible to create a notification from a background service.
You create the Notification using the Notification.Builder class, setting things like title, icon, text, when to display it and also the intent to launch when the user clicks on the notification (used to open your app at a desired location). Once created you then use the startForeground(NOTIFICATION_ID,notification). You specify an id so you can access the notification later.
Is it possible (i'm sure it is because i've seen other apps do it) to know when the clear notifications button is pressed without having an active notification?
For instance, I need to know if the user has an SMS notification, if he pushes clear I would like to be told. Is there a callback for this?
Is it possible (i'm sure it is because i've seen other apps do it) to know when the clear notifications button is pressed without having an active notification?
No, it is not possible.
I need to know if the user has an SMS notification
No, you do not. For starters, there are a few hundred SMS clients, many of which will use Notifications, so there is no singular "SMS notification". And, as noted, you do not have any means of determining when other applications add or remove Notifications.
At present i am working on c2dm in android.i am sending messages from server but messages are displaying on Log cat.But i want to display dialog when message occur how can i do this.
Please help me.
Maybe you should use the notifications framework to notify the user by dropping an icon in the notification bar. This is less obtrusive, but gives the user some visual cue that something has happened.
First, you cannot display dialog boxes from broadcast receivers. At most, you can start up an activity, perhaps one themed to look like a dialog.
Second, popping up an activity like this is generally frowned upon. You have no idea what the user is doing at the time, and they may not appreciate your activity taking over the foreground. Only a select handful of applications (VOIP clients, alarm clocks, etc.) should do this sort of thing.
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.