私は特定の時間をスケジュールし、Firebaseを使用して通知を送信しようとしています。私は試合開始前に通知を送信しなければならないプロジェクトに取り組んでいます。現在、私の通知はリアルタイムで行われていますが、特定の時間にスケジュールを設定する方法が見つかりません。特定の時間にFirebase通知を送信するにはどうすればいいですか?
リアルタイムで私はこの特定のコードを使用しています。あなたは、コードを経由してこれらを達成するための別の方法をしたい場合はhttps://firebase.google.com/docs/notifications/
が、私はあなたがあなたの通知をスケジュールすることをお勧め:
//Class extending service as it is a service that will run in background
public class NotificationFirebaseListener extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
String test;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.e(TAG, "From: " + remoteMessage.getFrom());
Log.e(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody() + "=====>");
if (remoteMessage.getData().size() > 0) {
Log.e(TAG, "Message data payload: " + remoteMessage.getData());
test = String.valueOf(remoteMessage.getData());
}
sendNotification(test);
}
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
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("Bus Tracking")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
保留中のインテントを持つアラームマネージャを使用します。 –
独自のApp Server経由で通知の送信を処理する必要があります。 –