2

I am trying to implement a rather common question in SMS notification.

I want to create a notification (which a custom view / text / etc) on the screen, but I want to cause minimal distraction to the user. I don't want to create an extra step of dragging down the notification bar and clicking it, which is what most stock messaging apps do anyways.

My initial implementation was to bring up a AlertDialog through a receiver, which works as it should, but of course takes control away from the user, which is not what I ultimately wanted.

My second implementation was to bring up a PopupWindow through an "invisible" activity. However, bringing up any Activity, as you probably know, takes focus of the current activity, so it will cause (at least) a 1 click distraction to the user, even if he can see what is still in the background.

My third implementation was a custom Toast -- this works fine, except it is not clickable and its lifetime is not well controlled.

So, knowing what I've implemented, I would like to ask if anyone knows or has a clue of how we would bring up a popup near the top without causing any distraction. I know several notification managers are able to do this.

Here is an example with Pops Notification. http://imageshack.us/photo/my-images/849/screenshot2012081618583.png/

programmer33
  • 642
  • 8
  • 19

1 Answers1

1

Why won't you just use a regular notification?

You can configure it so it can make the phone vibrate, make sound and even change the led color (if supported).

Here is a simple method that I use all the time to provide a notification:

NOTE: In order for the vibration to work, you have to add to your manifest:

<uses-permission android:name="android.permission.VIBRATE" >

The method:

public static void sendNotification(Context caller, Class<?> activityToLaunch, String title, String msg, int numberOfEvents,boolean sound, boolean flashLed, boolean vibrate,int iconID) {
    NotificationManager notifier = (NotificationManager) caller.getSystemService(Context.NOTIFICATION_SERVICE);

    final Notification notify = new Notification(iconID, "", System.currentTimeMillis());

    notify.icon = iconID;
    notify.tickerText = title;
    notify.when = System.currentTimeMillis();
    notify.number = numberOfEvents;
    notify.flags |= Notification.FLAG_AUTO_CANCEL;
    if (sound) notify.defaults |= Notification.DEFAULT_SOUND;

    if (flashLed) {
    // add lights
        notify.flags |= Notification.FLAG_SHOW_LIGHTS;
        notify.ledARGB = Color.CYAN;
        notify.ledOnMS = 500;
        notify.ledOffMS = 500;
    }

    if (vibrate) {
        notify.vibrate = new long[] {100, 200, 300};
    }

    Intent toLaunch = new Intent(caller, activityToLaunch);
    toLaunch.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    toLaunch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent intentBack = PendingIntent.getActivity(caller, number, toLaunch, 0);

    notify.setLatestEventInfo(caller, title, msg, intentBack);   
    notifier.notify(number, notify);
    number = number+1;
}
RE6
  • 2,684
  • 4
  • 31
  • 57
  • If i want to put a custom image and the message and notify the user, it would be a lot more convenient to have this pop up come up in the background, versus just adding another notification to their notification manager (whats the point then, is that not what the stock sms app does already?). I have looked into enough options before asking. I'm already familiar with notification manager. – programmer33 Aug 17 '12 at 16:45
  • 1
    Oh, I didn't know that you want an application that will replace the stock SMS app... – RE6 Aug 17 '12 at 16:46