2017-12-13 8 views
-3

내 앱에 FCM (Firebase Cloud Messaging)을 사용합니다. 알림으로 현재 활동 계속하기

나는 내 응용 프로그램에서 N 활동이 그 활동의 스택 할 수 있습니다 응용 프로그램의 수명 동안

:

Activity1 ->Activity2 ->Activity3 -> ... ->ActivityN

I을 행동을 원한다 :

  1. ActivityN
  2. 전원을 켜고 응용 프로그램이 그것을 달성하는 방법

ActivityN에

  • 표시 대화 ActivityN에 전경 통지에 배경
  • 클릭 6,
  • 턴 응용 프로그램? FirebaseMessagingService 클래스

  • 답변

    0

    은 >> 당신이하는 활동 알림 클릭에 공개 될 것이 확실하지 않은 사용자의 경우

    Intent intent = new Intent(this, ActivityN.class); 
         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
         PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 
           FLAG_ONE_SHOT); 
    
    
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
          .setSmallIcon(R.drawable._logo) 
          .setContentText(notification) 
          .setContentTitle(title) 
          .setAutoCancel(true) 
          .setSound(defaultSoundUri); 
          .setContentIntent(pendingIntent); 
    
        NotificationManager notificationManager = 
          (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    
        notificationManager.notify(0, notificationBuilder.build()); 
    
    +0

    ActivityN 대신 어떤 활동을 배치해야하는지 어떻게 알 수 있습니까? 액티비티 스택의 마지막 위치에 응용 프로그램의 모든 활동이있을 수 있습니다. –

    +0

    Gloabal 활동에서 정적 gloabal 변수 만들기 AactivityName = this 및 wehenver처럼 activityName = this와 같이 새 Activity로 이동하십시오. GloabalActivity.ActivityName으로 firebase 서비스의 이름을 확인하십시오. –

    0

    을 onMessageRecived. 그런 다음 알림을 클릭하여 브로드 캐스팅해야합니다. 브로드 캐스트 리시버 만들기.

    <receiver 
         android:name=".NotificationClickReceiver" 
         /> 
    

    매니페스트

    에서

    class NotificationClickReceiver extends BroadcastReceiver{ 
    
        @Override 
        public void onReceive(Context context, Intent intent) { 
         // here you will get Intent 
         // Check which activity is currently open and pass the data to it 
         // For passing data you can use a Another BroadcastReceiver or 
        } 
    } 
    

    항목은 다음 알림 클릭에 getBroadcast하는 pendingIntent를 사용

    Intent intent = new Intent(this, NotificationClickReceiver.class); 
        intent.putExtra("key","val"); 
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 3, intent, 
          PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); 
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
          .setSmallIcon(R.drawable._logo) 
          .setContentText(notification) 
          .setContentTitle(title) 
          .setAutoCancel(true) 
          .setSound(defaultSoundUri); 
         .setContentIntent(pendingIntent); 
    
        NotificationManager notificationManager = 
          (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    
        notificationManager.notify(0, notificationBuilder.build()); 
    

    다음 NotificationClickReceiver onReceive의 의도를 알아낼 수 지금 당신은 얻을 것이다 어떤 활동에 전달할 것인가.

    +0

    답변에서 YourActivity를 선언했지만 어떤 활동이 있습니까? 앱이 포 그라운드로 이동하면 스택에 마지막으로 활동이있을 수 있습니다. 또한, Intent.FLAG_ACTIVITY_CLEAR_TOP 내 스택에있는 다른 모든 활동을 제거합니다. 활동 스택을 변경하지 말고 대화 상자 만 표시해야합니다. –

    +0

    알림 클릭시 열려고하는 Whch 활동. – ADM

    +0

    앱이 백그라운드로 바뀌면 순간 내 활동 스택의 마지막 활동을 열고 싶습니다. 그것은 Activity1, Activity2, ... 일 수 있습니다. ActivityN, 어떤 활동이 될지 모르겠습니다. –