Уведомление Firebase PendingIntent возвращает нулевое значение - AndroidX - PullRequest
1 голос
/ 17 февраля 2020

Я уже искал все источники из целого rnet, как вернуть значение из ожидающего намерения, когда пользователь щелкает уведомление, он запускает MainActivity, но IntentExtra был нулевым, это мой код

public class FirebaseNotificationManager extends FirebaseMessagingService {

private static final String TAG = "Firebase_MSG";
@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.
    sendNotification(remoteMessage.getFrom(), remoteMessage.getNotification().getBody());
    Log.d(TAG, "From: " + remoteMessage.getFrom());
    Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
}

private void sendNotification(String messageTitle, String messageBody) {

    Intent intent = new Intent(this, ResultActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK  | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.putExtra("NotificationJumpPKG", "SignUp");
    PendingIntent pendingIntent = PendingIntent.getActivity(FirebaseNotificationManager.this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.primary_applogo)
            .setContentTitle(messageTitle)
            .setContentText(messageBody)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent)
            .setAutoCancel(true)
            .setPriority(NotificationCompat.PRIORITY_HIGH);


    NotificationManagerCompat mNoticationMgr = NotificationManagerCompat.from(FirebaseNotificationManager.this);
    mNoticationMgr.notify(1, notificationBuilder.build());
}

}

// MainActivity. java

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


    Intent intent = getIntent();
    String mNotificationJump = intent.getStringExtra("NotificationJumpPKG");
    Toast.makeText(MainActivity.this, "Dapat" + mNotificationJump, Toast.LENGTH_SHORT).show();
    if (mNotificationJump != null) {
        if (mNotificationJump.equals("SignUp")) {
            Intent intent1 = new Intent(MainActivity.this, SignupFormActivity.class);
            startActivity(intent1);
        } else if (mNotificationJump.equals(("SearchFinal"))) {
            Intent intent1 = new Intent(MainActivity.this, SearchFinalActivity.class);
            startActivity(intent1);
        }
    }
}
...