I've looked fairly extensively across a wide range of terminology ("banner", "pop down", "notification type") and I can't seem to find clarity on what I 'think' is a very common issue. So if there is a very obvious solution I missed due to my lack of terminology please advice.
The problem is this: I want an Android notification to appear as a "banner" that drops down from the top of the screen (if banner is the wrong word for this please advise). I went through the Docs and didn't seem to across a setting that toggles this behaviour. Here is an example of what I would like:
I have the notification working but it currently only showing up inside the drawer. It's not popping down from the drawer (which is what I want).
Here is my code, if you can advise how I can make it also appear as a banner I would greatly appreciate it:
public void createNotification(Context context, Bundle extras)
{
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String appName = getAppName(this);
Intent notificationIntent = new Intent(this, PushHandlerActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.putExtra("pushBundle", extras);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
int defaults = Notification.DEFAULT_ALL;
if (extras.getString("defaults") != null) {
try {
defaults = Integer.parseInt(extras.getString("defaults"));
} catch (NumberFormatException e) {}
}
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setDefaults(defaults)
.setSmallIcon(context.getApplicationInfo().icon)
.setWhen(System.currentTimeMillis())
.setContentTitle("NotificationTitle")
.setTicker(extras.getString("title"))
.setContentIntent(contentIntent)
.setAutoCancel(true);
String messageJson = extras.getString("data");
JSONObject parsed;
String message = null;
try {
parsed = new JSONObject(messageJson);
message = parsed.getString("message");
} catch (JSONException e) {
e.printStackTrace();
}
if (message != null) {
mBuilder.setContentText(message);
} else {
mBuilder.setContentText("Notification");
}
String msgcnt = extras.getString("msgcnt");
if (msgcnt != null) {
mBuilder.setNumber(Integer.parseInt(msgcnt));
}
int notId = 0;
try {
notId = Integer.parseInt(extras.getString("notId"));
}
catch(NumberFormatException e) {
Log.e(TAG, "Number format exception - Error parsing Notification ID: " + e.getMessage());
}
catch(Exception e) {
Log.e(TAG, "Number format exception - Error parsing Notification ID" + e.getMessage());
}
mNotificationManager.notify((String) appName, notId, mBuilder.build());
}