1

알림 클릭 이벤트에 대한 세부 활동을 열려고합니다. 여기에 PendingIntentNotification 클래스가 있습니다. 추가 된 addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)도 추가되었습니다. PendingIntent.FLAG_UPDATE_CURRENT. 나는 사이트에서 모든 주제를 검색해이 솔루션을 찾았습니다. 모두 시도해 보았습니다. 여기 FCM 알림이 작동하지 않는 PendingIntent

public class MyFirebaseMessagingService extends FirebaseMessagingService { 

    private static final String TAG = "MyFirebaseMsgService"; 
    /** 
    * Called when message is received. 
    * 
    * @param remoteMessage Object representing the message received from Firebase Cloud Messaging. 
    */ 
    // [START receive_message] 
    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     // TODO(developer): Handle FCM messages here. 
     // If the application is in the foreground handle both data and notification messages here. 
     // Also if you intend on generating your own notifications as a result of a received FCM 
     // message, here is where that should be initiated. See sendNotification method below. 
     Log.d(TAG, "From: " + remoteMessage.getFrom()); 
     Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody()); 

     ArrayList<String> notificationData = new ArrayList<String >(remoteMessage.getData().values()); 
     String fortuneID = notificationData.get(0); 
     sendNotification(remoteMessage.getNotification().getBody(),fortuneID); 
    } 
    // [END receive_message] 

    /** 
    * Create and show a simple notification containing the received FCM message. 
    * 
    * @param messageBody FCM message body received. 
    */ 
    private void sendNotification(String messageBody,String notificationID) { 

     Intent configureIntent = new Intent(getApplicationContext(), FalDetayActivity.class); 
     configureIntent.putExtra("extra", "123123"); 
     configureIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     configureIntent.setAction("dummy_unique_action_identifyer" + "123123"); 
     int dummyuniqueInt = new Random().nextInt(543254); 
     PendingIntent pendingClearScreenIntent = PendingIntent.getBroadcast(getApplicationContext(), dummyuniqueInt, configureIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

     Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 

     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
       .setSmallIcon(R.mipmap.ic_launcher) 
       .setContentTitle("myApp") 
       .setContentText(messageBody) 
       .setAutoCancel(true) 
       .setSound(defaultSoundUri) 
       .setContentIntent(pendingClearScreenIntent); 

     NotificationManager notificationManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

     notificationManager.notify(1 /* ID of notification */, notificationBuilder.build()); 
    } 
} 

getBundle 부분 MainActivity

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     String quote = getIntent().getStringExtra("extra"); 

     ... 
} 

또 다른 내가 FalDetailActivity을 열려는 문제가 있지만 항상 항상 열려 MainActiviygetIntent() null을 반환합니다. 아마, PendingIntent이 설정되지 않았습니다.이 코드를 확인하시기 바랍니다. 감사합니다 ... 뭔가

당신은 브로드 캐스트를 보낼 수 없습니다, 보류중인 의도로 활동을 시작하려는
 Intent configureIntent = new Intent(getApplicationContext(), FalDetayActivity.class); 
     configureIntent.putExtra("extra", "123123"); 
     configureIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     PendingIntent pendingClearScreenIntent = PendingIntent.getActivity(getApplicationContext(), 0, configureIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
+0

** configureIntent.setAction ("dummy_unique_action_identifyer"+ "123123"); ** 이 줄과 try를 제거하십시오. –

+0

나는 아직도 대신 ** PendingIntent.getBroadcast() **이 사용 ** PendingIntent.getActivity() ** –

+0

작동하지 제거 펼친 상태 항목이 클릭됩니다. 이것이 활동 인 경우 ** FLAG_ACTIVITY_NEW_TASK ** 플래그를 포함해야합니다. 이 플래그를 추가하십시오. –

답변

1

마지막으로 해결책을 찾았습니다. https://firebase.google.com/docs/notifications/android/console-audience

앱이 백그라운드에서 실행되면 알림 메시지가 표시됩니다. 시스템 트레이. 사용자가 알림을 탭하면 기본적으로 앱 실행기가 열립니다.

여기에는 알림 및 데이터 페이로드가 모두 포함 된 메시지가 포함됩니다. 이러한 경우 알림은 장치의 시스템 트레이로 전달되며 데이터 페이로드는 실행기 작업의 의도에 따라 추가로 제공됩니다.

+0

데이터 페이로드 뒤에있는 코드는 무엇입니까?전체 코드를 말해 줄 수 있니? 백그라운드에서 app을 호출하면 onMessageRecive 메소드가 호출되지 않습니다. 그러면 클래스에서 데이터 페이로드를 어떻게 얻을 수 있습니까? 코드는 무엇입니까? 말해주십시오. –

+0

솔루션을 찾았다면 다행입니다 만, 런처 활동에서 데이터를 어디서 받습니까? 나는 그것을 어디에서도 발견 할 수 없다. – jobbert

0

getActivity-getBroadcast를 업데이트하고 제거

UPDATE. PendingIntent.getBroadcast(...) ~ PendingIntent.getActivity(...)으로 변경하십시오.

getApplicationContext()을 사용하는 대신 getApplicationContext()this으로 바꿔 서비스의 컨텍스트를 사용해보십시오. 보류중인 의도에 대한 이러한 플래그를, 또한

configureIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

사용 - - 당신이 서비스의 컨텍스트에서 활동을 시작하기 때문에

은 또한 새 작업 의도 플래그를 추가 할 필요가

PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT 
+0

질문을 업데이트했지만 여전히 작동하지 않습니다. –

관련 문제