1

firebase를 사용하여 알림을 보내고 있습니다. 사용자가 알림을 클릭하면 ResultActivity가 열립니다. 앱이 포 그라운드에있을 때 제대로 작동합니다. 그러나 앱이 백그라운드에있을 때 ResultActivity가 아닌 HomeActivity (앱의 런처 활동)를 엽니 다. 문제가 뭔지 이해가 안되니?왜 PendingIntent가 특정 활동이 아닌 앱의 런처 활동을 여는 이유가 무엇입니까?

public class MyFirebaseMessagingService extends FirebaseMessagingService { 

    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); 
     notificationBuilder.setContentTitle(getResources().getString(R.string.app_name)); 
     notificationBuilder.setContentText(remoteMessage.getNotification().getBody()); 
     notificationBuilder.setAutoCancel(true); 
     notificationBuilder.setSmallIcon(R.mipmap.ic_launcher); 

     Intent intent = new Intent(getApplicationContext(), ResultActivity.class); 

     PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT); 

     notificationBuilder.setContentIntent(pendingIntent); 
     NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     notificationManager.notify(0, notificationBuilder.build()); 

    } 
} 
+3

마지막으로 새 질문을하기 전에 몇 가지 검색을 어제 질문을 받았다이 정확한 질문 –

+0

http://stackoverflow.com/questions/40718155로 이동해야합니다/open-specific-activity-when-notification-click-in-fcm –

+1

[여기] (http://stackoverflow.com/questions/37407366/firebase-fcm-notifications-click-action-payload)를보십시오. 도움이 될지도 모릅니다. –

답변

0

이것은 click_action 매핑을 테스트하는 좋은 방법입니다.

<intent-filter> 
    <action android:name="OPEN_ACTIVITY_1" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
</intent-filter> 

또한, 앱이 배경에있는 경우에만 동작합니다, 기억 : 그것은 FCM의 문서에 지정된 같은 텐트 필터를 필요로한다. 포어 그라운드에 있다면 FirebaseMessagingService의 확장을 구현해야합니다. onMessageReceived 방법, 수동으로 click_action 대상

@Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
    //This will give you the topic string from curl request (/topics/news) 
    Log.d(TAG, "From: " + remoteMessage.getFrom()); 
    //This will give you the Text property in the curl request(Sample  Message): 
    Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody()); 
    //This is where you get your click_action 
    Log.d(TAG, "Notification Click Action: " + remoteMessage.getNotification().getClickAction()); 
    //put code here to navigate based on click_action 
    }