이제 Firebase 콘솔에서 테스트 메시지를 보내고 휴대 전화로 푸시 알림을받을 수 있습니다. 지금 인앱 알림 생성에 대한 몇 가지 질문이 있습니다. 이것은 내 현재 레이아웃입니다.
I want the push notifications to appear as in-app notifications in my app too. The only class handling the message is MyFirebaseMessagingService
class which includes a notificationHelper
to help build the notification. How do I pass the message information from MyFirebaseMessagingService
to the Notification Fragment I have now? Do I need to store the information in a local file then retrieve the information from the local file to be used in Notification Fragment again? What is the best approach in this case?
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
if (remoteMessage.getNotification() != null) {
String title = remoteMessage.getNotification().getTitle();
String body = remoteMessage.getNotification().getBody();
NotificationHelper.displayNotification(getApplicationContext(), title, body);
}
}
}
Another trivial question is about the FCM token issue. I have already created a FCM token. How do I make the app to check if a token has been generated to prevent the token be generated every time I launch the app?
if(instanceIdResult.getToken() == null)
{
//generate token
}
Can I write the code like this?
다음과 같이 현재 토큰을 검색 할 수 있습니다.
FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
Log.w(TAG, "getInstanceId failed", task.getException());
return;
}
String token = task.getResult().getToken();
}
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다