2017-04-11 50 views
0

我的代碼如下所示:如何在前臺顯示通知,而不是在狀態欄上顯示通知圖標?

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應用程序圖標。但是我想要做的是,我想顯示正確的通知,就像應用程序未運行時一樣。

+1

http://stackoverflow.com/documentation/android/1347/notifications/6379/heads-up-notification-with-ticker-for-較舊的設備#噸= 201704111731180003099 –

回答

1

嘗試setLargeIcon(R.mipmap.ic_launcher)。 如果它不會幫助,嘗試添加:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notificationBuilder.setPriority(Notification.PRIORITY_HIGH); }

相關問題