Android-通知バーで通知を安定させます
-
26-10-2019 - |
質問
通知バーで通知と表示する関数を書きました。
private void showNotification()
{
CharSequence title = "Hello";
CharSequence message = "Notification Demo";
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon, "A Notification", System.currentTimeMillis());
Intent notificationIntent = new Intent(this, Main_Activity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(Main_Activity.this, title, message, pendingIntent);
notificationManager.notify(NOTIFICATION_ID, notification);
}
その正常に動作しますが、 what way we can keep the notification steady at Notification bar
ユーザーが通知バーから「クリア」通知ボタンを押したときでさえ?
「Yahoo」アプリケーションの通知バーをご覧ください。
私はこのSDKの記事を経験しました: http://developer.android.com/guide/topics/ui/notifiers/notifications.html#updating 、しかし、見つけることができませんでした。
解決
使用する FLAG_NO_CLEAR
あなたにそれを設定するだけです Notification
それを提供する前にインスタンス NotificationManager
:
notificaton.flags |= Notification.FLAG_NO_CLEAR;
編集: あなたが使用している場合、私はちょうどそれに気づきました Notification.Builder
(Honeycomb以降)、通知を「継続」しますが、「すべてのクリア」に対して免疫になります。見る ここ.
見た目は、これは開発者が FLAG_NO_CLEAR
ユーザーを混乱させる可能性があるため、非向きの通知ではありません。
他のヒント
試す Setongoing(True)。
notification = new Notification.Builder(getApplicationContext())
.setLargeIcon(
BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
.setSmallIcon(R.drawable.ic_launcher).setTicker(tickerText)
.setWhen(System.currentTimeMillis()).setContentTitle(contentTitle)
.setOngoing(true)
.setContentText(contentText)
.setContentIntent(contentIntent)
所属していません StackOverflow