Reputation: 4517
My code is as shown below:
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, OrderHistory.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(Consts.NOTIFICATION_ORDER_ID, notificationMap.get(Consts.NOTIFICATION_ORDER_ID));
intent.putExtra(Consts.NOTIFICATION_ORDER_STATUS,
notificationMap.get(Consts.NOTIFICATION_ORDER_STATUS));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("QuFlip")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
Now, whenever the notification comes,it shows android bydefault app icon in statusbar. But what I want to do is, I want to show proper notification, just like when the app is not running.
Upvotes: 1
Views: 495
Reputation: 52386
Set the PRIORITY_HIGH and DEFAULT_SOUND flags:
notification.setPriority(Notification.PRIORITY_HIGH);
notification.setDefaults(NotificationCompat.DEFAULT_SOUND);
It also works if you set DEFAULT_VIBRATE but that's more intrusive.
Upvotes: 1
Reputation: 665
Try setLargeIcon(R.mipmap.ic_launcher). If it's won't help, try to add:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
}
Upvotes: 2