0

FCMメッセージサービスのonMessageReceivedの中に以下のコードを実装して、アプリがフォアグラウンドのときに通知を表示しました。Android - 数秒前に通知トレイを持たせる方法

通知が正しく生成され、正しくトレイに表示されます。 しかし、私の必要条件は、アプリが数秒間前に来るように通知トレイをフォアグラウンドにしてから、デフォルトで非表示にする必要があるということです。これを達成する方法は?

NotificationCompat.Builder notificationBuilder = new 
NotificationCompat.Builder(this) 
       .setSmallIcon(R.drawable.ic_notifications_black_24dp) 
       .setContentTitle(title) 
       .setContentText(messageBody) 
       .setAutoCancel(true) 
       .setContentIntent(pendingIntent); 
NotificationManager notificationManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

notificationManager.notify(2 , notificationBuilder.build()); 

おかげ

+0

答えがあなたを助けましたか? –

答えて

0

Notification.PRIORITY_HIGHに設定された通知の優先度やNotification.PRIORITY_MAX

1

あなたがプログラムで通知トレイを表示したいのであれば、次の操作を行います。また、

Object sbservice = getSystemService("statusbar"); 
Class<?> statusbarManager = Class.forName("android.app.StatusBarManager"); 
Method showsb; 
if (Build.VERSION.SDK_INT >= 17) { 
    showsb = statusbarManager.getMethod("expandNotificationsPanel"); 
} 
else { 
    showsb = statusbarManager.getMethod("expand"); 
} 
showsb.invoke(sbservice); 

あなたはマニフェストに次のアクセス許可を追加する必要があります。

<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" /> 
関連する問題