我的代码如下所示:
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());
}
现在,每当通知到来时,它会在状态栏中显示android bydefault app图标。但我想要做的是,我想显示正确的通知,就像应用程序没有运行时一样。
答案 0 :(得分:1)
尝试setLargeIcon(R.mipmap.ic_launcher)。 如果它没有帮助,请尝试添加:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
}
答案 1 :(得分:1)
设置PRIORITY_HIGH和DEFAULT_SOUND标志:
notification.setPriority(Notification.PRIORITY_HIGH);
notification.setDefaults(NotificationCompat.DEFAULT_SOUND);
如果您设置了DEFAULT_VIBRATE,它也可以工作,但是更具侵入性。