It can be done via Headsup notification. It is feature of Andorid L
so by code here is demo
Notification createNotification(boolean makeHeadsUpNotification) {
Notification.Builder notificationBuilder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setPriority(Notification.PRIORITY_DEFAULT)
.setContentTitle("Sample Notification")
.setContentText("This is a normal notification.");
if(Build.VERSION.SDK_INT> Build.VERSION_CODES.KITKAT)
{
notificationBuilder.setCategory(Notification.CATEGORY_MESSAGE);
}
if (makeHeadsUpNotification) {
Intent push = new Intent();
push.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
push.setClass(this, IndexActivity.class);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
push, PendingIntent.FLAG_CANCEL_CURRENT);
notificationBuilder
.setContentText("Heads-Up Notification on Android L or above.")
.setFullScreenIntent(fullScreenPendingIntent, true);
}
return notificationBuilder.build();
}
you can call it like
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context
.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, createNotification(
true));