2016-09-27 6 views
0

특정 시간을 예약하려고하고 있으며 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()); 
    } 


    } 
+0

경보 관리자를 보류중인 의도와 함께 사용하십시오. –

+0

자신의 응용 프로그램 서버를 통해 알림 전송을 처리해야합니다. –

답변

관련 문제