0
그래서 firebase 메시징에서 이상한 동작이 발생합니다. 내 firebase 메시징 FCM 호출에서 [알림]과 [데이터] 개체를 모두 보내고 있습니다. 앱이 백그라운드에있을 때 FCM 요청을 호출하는만큼 푸시 알림을받을 수 있습니다. 하지만 문제는 이제 응용 프로그램을 여는 동안 푸시 알림을 받으면 알림을 클릭하면 더 이상 푸시 알림을받지 않게됩니다.전경에 앱이있는 동안 푸시 알림을 받으면 Firebase 메시징이 중지됩니다.
참고 : 강제로 다시 시작한 다음 다시 열면 알림이 다시 전송됩니다.
여러 Android 기기에서이 문제를 테스트했으며 동일한 결과가 나타납니다.
Btw, 나는 compile 'com.google.firebase:firebase-messaging:11.4.0'
을 사용하고 있습니다.
UPDATE : 여기에 어떤 문제가 발생 내가 찾은 코드
public class GcmMessageHandler extends FirebaseMessagingService {
public static final int MESSAGE_NOTIFICATION_ID = 435345;
String title, Type, Link, AppVersion, discountExpiry, discountValue, status,
phone, nid;
PreferencesHelper ph;
Map data;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (Looper.myLooper() == null) {
Looper.prepare();
}
ph = new PreferencesHelper(getApplicationContext());
data = remoteMessage.getData();
String click_action = remoteMessage.getNotification().getClickAction();
Intent intentNotifi = new Intent(click_action);
intentNotifi.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
title = (String) data.get("title");
Type = (String) data.get("type");
Link = (String) data.get("link");
discountExpiry = (String) data.get("discountexpiry");
discountValue = (String) data.get("discvalue");
AppVersion = (String) data.get("appversion");
status = (String) data.get("status");
phone = (String) data.get("delivery_phone");
nid = (String) data.get("nid");
if (Type != null) {
Intent notificationIntent;
switch (Type) {
case "simple_notification":
notificationIntent = new Intent(getApplicationContext(), SplashActivity.class);
show_notification(title, notificationIntent);
break;
case "order_status":
notificationIntent = new Intent(getApplicationContext(), OrderActivity.class);
notificationIntent.putExtra("fromNotification", true);
show_notification(title, notificationIntent);
break;
case "news":
notificationIntent = new Intent(getApplicationContext(), DetailsFromNotification.class);
notificationIntent.putExtra("nidRef", nid);
notificationIntent.getBooleanExtra("fromNotification", true);
show_notification(title, notificationIntent);
break;
case "link":
notificationIntent = new Intent(Intent.ACTION_VIEW);
notificationIntent.setData(Uri.parse(Link));
show_notification(title, notificationIntent);
break;
case "deal_notify":
notificationIntent = new Intent(getApplicationContext(), DealsActivity.class);
notificationIntent.putExtra("fromNotification", true);
show_notification(title, notificationIntent);
break;
case "after_ordering":
notificationIntent = new Intent(getApplicationContext(), OrderActivity.class);
notificationIntent.putExtra("fromNotification", true);
show_notification(title, notificationIntent);
break;
case "no_orders":
notificationIntent = new Intent(getApplicationContext(), SplashActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
show_notification(title, notificationIntent);
break;
case "no_signup":
notificationIntent = new Intent(getApplicationContext(), UserActivity.class);
notificationIntent.putExtra("fromNotification", true);
show_notification(title, notificationIntent);
break;
case "user_points":
notificationIntent = new Intent(getApplicationContext(), PointsActivity.class);
notificationIntent.putExtra("fromNotification", true);
show_notification(title, notificationIntent);
break;
default:
notificationIntent = new Intent(getApplicationContext(), SplashActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
show_notification(title, notificationIntent);
break;
}
}
Looper.loop();
}
private void show_notification(String title, Intent intent) {
Context context = getBaseContext();
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(getNotificationIcon()).setContentText(title).
setContentIntent(contentIntent)
.setAutoCancel(true).setDefaults(Notification.DEFAULT_SOUND |
Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build());
}
private int getNotificationIcon() {
boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >=
android.os.Build.VERSION_CODES.LOLLIPOP);
return useWhiteIcon ? R.drawable.logo_notification :
R.drawable.logo_notification;
}
}
푸시 알림을 처리하는 코드 게시 –
@JuanCruzSoler 코드가 – hhyari
인 제 질문을 업데이트합니다. https://firebase.google.com/docs/cloud-messaging/android/first-message 문서를 정상적으로 정상적으로 처리합니다. 앱이 배경 화면에있는 경우에만 알림이 표시됩니다. –