0

나는 푸시 알림 기능을 사용하여 Firebase 기능을 사용하고 있습니다. 그러나 특정 유형의 알림을 클릭하면 알림을받은 후 애플리케이션을 열지 않고 전화 설정 (Wi-Fi 설정 또는 테스트중인 전화에 따라 애플리케이션 선택 대화 상자)으로 이동합니다. 아래는 FirebaseMessagingService 코드입니다.알림을 클릭하면 응용 프로그램을 열지 않고 전화 시스템 설정으로 이동합니다.

@Override 
public void onMessageReceived(RemoteMessage remoteMessage) { 
    super.onMessageReceived(remoteMessage); 

    Log.d(TAG, "onMessageReceived: url is " + remoteMessage.getData().get("avatar_url")); 

    myRef = FirebaseDatabase.getInstance().getReference(); 


    NotificationCompat.Builder mBuilder = 
      new NotificationCompat.Builder(getApplicationContext(), channelId) 
      .setSmallIcon(R.mipmap.ic_launcher) 
      .setContentTitle(remoteMessage.getData().get("title")) 
      .setContentText(remoteMessage.getData().get("body")) 
      .setLargeIcon(ImageManager.getBitmapFromUrl(remoteMessage.getData().get("avatar_url"))); 

    type = remoteMessage.getData().get("type"); 
    userName = remoteMessage.getData().get("title"); 
    Log.d(TAG, "onMessageReceived: username is " + userName); 
    uid = remoteMessage.getData().get("uid"); 
    Log.d(TAG, "onMessageReceived: uid is " + uid); 
    chatId = remoteMessage.getData().get("chatId"); 
    Log.d(TAG, "onMessageReceived: chatId is " + chatId); 
    notificationId = remoteMessage.getData().get("notificationId"); 
    Log.d(TAG, "onMessageReceived: notification id is " + notificationId); 


    if(type.equals("message")){ 

     Intent resultIntent = new Intent("android.intent.action.MESSAGING"); 
     resultIntent.putExtra("chatId", chatId); 
     resultIntent.putExtra("uid", uid); 
     resultIntent.putExtra("userName", userName); 

     PendingIntent resultPendingIntent = 
       PendingIntent.getActivity(
         getApplicationContext(), 
         0, 
         resultIntent, 
         PendingIntent.FLAG_UPDATE_CURRENT 
       ); 

     mBuilder.setContentIntent(resultPendingIntent); 
     mBuilder.setAutoCancel(true); 

     myRef.child("notifications") 
       .child(FirebaseAuth.getInstance().getCurrentUser().getUid()) 
       .child(notificationId) 
       .setValue(null); 

    } else { 

     //Getting problem here 

     Intent resultIntent = new Intent("android.intent.action.MAIN"); 
     resultIntent.putExtra("FragmentIndicator", "2"); 

     PendingIntent resultPendingIntent = 
       PendingIntent.getActivity(
         getApplicationContext(), 
         0, 
         resultIntent, 
         PendingIntent.FLAG_UPDATE_CURRENT 
       ); 

     mBuilder.setContentIntent(resultPendingIntent); 
     mBuilder.setAutoCancel(true); 

     myRef.child("notifications") 
       .child(FirebaseAuth.getInstance().getCurrentUser().getUid()) 
       .child(notificationId) 
       .setValue(null); 

    } 

    int mNotificationId = (int) System.currentTimeMillis(); 
    NotificationManager mNotifyMgr = 
      (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    mNotifyMgr.notify(mNotificationId, mBuilder.build()); 

} 

이 논리는 if(type.equals("message"))이면 모두 정상적으로 작동합니다. 그러나 문제는 친구 요청 또는 친구 요청 확인의 알림 유형을 포함하는 else 문을 사용하는 경우입니다.이 경우 내 채팅 부분으로 사용자를 안내하려는 경우입니다. 주요 활동에 대한

내 매니페스트는 다음과 같이이다 :

<activity 
     android:name=".HomeActivity" 
     android:windowSoftInputMode="adjustPan"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN"/> 
      <category android:name="android.intent.category.LAUNCHER"/> 
     </intent-filter> 
    </activity> 

잘못 여기에 무슨 일이 있었는지 어떤 아이디어가? 매우 감사.

답변

1

계류중인 의도에 시스템 수준의 의도를 부여하면 시스템 설정이 열립니다. 대신 HomeActivity.class 또는 응용 프로그램의 매니 페스트에 정의 된 응용 프로그램의 다른 활동을 제공해야합니다.

여기 있습니다.

if(type.equals("message")){ 

    Intent resultIntent = new Intent(getApplicationContext(),HomeActivity.class); 
    resultIntent.putExtra("chatId", chatId); 
    resultIntent.putExtra("uid", uid); 
    resultIntent.putExtra("userName", userName); 

    PendingIntent resultPendingIntent = 
      PendingIntent.getActivity(
        getApplicationContext(), 
        0, 
        resultIntent, 
        PendingIntent.FLAG_UPDATE_CURRENT 
      ); 

    mBuilder.setContentIntent(resultPendingIntent); 
    mBuilder.setAutoCancel(true); 

    myRef.child("notifications") 
      .child(FirebaseAuth.getInstance().getCurrentUser().getUid()) 
      .child(notificationId) 
      .setValue(null); 

} else { 

    //Getting problem here 

    Intent resultIntent = new Intent(getApplicationContext(),HomeActivity.class); 
    resultIntent.putExtra("FragmentIndicator", "2"); 

    PendingIntent resultPendingIntent = 
      PendingIntent.getActivity(
        getApplicationContext(), 
        0, 
        resultIntent, 
        PendingIntent.FLAG_UPDATE_CURRENT 
      ); 

    mBuilder.setContentIntent(resultPendingIntent); 
    mBuilder.setAutoCancel(true); 

    myRef.child("notifications") 
      .child(FirebaseAuth.getInstance().getCurrentUser().getUid()) 
      .child(notificationId) 
      .setValue(null); 

} 
+0

쿨! 이제 작동합니다. 고마워요! – user8795747

+0

행복한 코딩 :) –