2016-08-12 47 views
0

我試圖顯示通知內容在Android 5.0及更高版本上彈出,但是我的編碼此功能只顯示android狀態欄上的小圖標,並且必須將狀態欄佈局節目收到通知的內容Android 6.0和更高版本的Android顯示通知內容

public static void createNotification(Context context, Class activity, String title, String subject) { 
    Intent intent = new Intent(context, activity); 
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    Bitmap icon = BitmapFactory.decodeResource(context.getResources(), 
      R.drawable.dollar); 
    Notification notify = new NotificationCompat.Builder(context) 
      .setAutoCancel(true) 
      .setContentTitle(title) 
      .setContentText(subject) 
      .setSmallIcon(R.mipmap.ic_launcher) 
      .setLargeIcon(icon) 
      .setPriority(0) 
      .setLights(Color.BLUE, 500, 500) 
      .setContentIntent(pendingIntent) 
      .build(); 

    notify.flags |= Notification.FLAG_AUTO_CANCEL; 
    NOTIFICATIONMANAGER = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE); 
    NOTIFICATIONMANAGER.notify(159753456, notify); 
} 

回答

2

您需要將優先以觸發的Android版本支持它擡頭通知設置爲高或最大:

Notification notify = new NotificationCompat.Builder(context) 
    // ... 
    .setPriority(NotificationCompat.PRIORITY_HIGH) 
    .setDefaults(NotificationCompat.DEFAULT_VIBRATE) 
    .build(); 

正如官方Notification documentation規定通知也需要振動或鈴聲產生擡頭通知:

通知具有高優先級,並且使用鈴聲或振動

另見this question上擡頭通知的詳細信息。

+0

不幸的是無法解決問題。我測試了在Android 6 –

+0

對不起,忘了提及你需要振動或鈴聲才能工作! – TR4Android

+0

非常感謝您的先生 –