Android OnGoing通知不适用于所有手机

时间:2018-03-07 06:36:51

标签: android notifications statusbar

我需要在状态栏中显示通知,即使该应用被杀死或从托盘中刷过。我使用onGoing(true)& Flag.onGoing_event。它适用于某些手机但不适用于所有手机。该怎么办?我需要类似下图的内容。

enter image description here

private void showNotificationBarState(String title, String body) {

    int mNotificationId = 5;

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.avatar_profile)
                    .setContentTitle(title)
                    .setContentText(body)
                    .setAutoCancel(true)
                    .setOngoing(true);


    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    //notificationBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;


    notificationBuilder.getNotification().flags |= Notification.FLAG_ONGOING_EVENT;
    notificationBuilder.getNotification().flags |= Notification.FLAG_FOREGROUND_SERVICE;


    assert notificationManager != null;
    notificationManager.notify(mNotificationId /* ID of notification */, notificationBuilder.build());


}

0 个答案:

没有答案