I know this is asked a million times before and I have tried everything I saw but I just cant make it work. I have data payload notification. Am getting them in onMessageReceived() but when I click the notification in notification tray it doesn't redirect to the launcher.
if (remoteMessage.getData().size() > 0) {
Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());
JSONObject data = json.getJSONObject("data");
Intent resultIntent = new Intent(getApplicationContext(), LandingActivity.class);
Bundle bundle = new Bundle();
bundle.putString("data", data.toString());
resultIntent.putExtras(bundle);
// image is present, show notification with image
//showNotificationMessageWithBigImage(getApplicationContext(), title, message, "13", resultIntent, profilePicThumb);
Intent intent = new Intent(this, LandingActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("FCM Message")
.setContentText("my message")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
and LandingActivity is the launcher activity of my app.
my manifest.xml
<activity
android:name=".landing.LandingActivity_"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.FullScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
When notification_payload with optional data_payload was given I got data in LandingActivity but when I get only data_payload the click redriection doesnt happen
the data-payload structure is like this
"data" :
{
"notification_type" : "QUIZ_WINNER",
"notification_message": "You hav won the quiz ",
"notification_data" : [
"user_id" : id,
"full_name" : full_name,
"profile_pic_thumb": user_profile_picthumb,
'quiz_id' : quiz_id,
'question_id' : question_id,
'quiz_title' : quiz_title,
],
"user_id" : from_id,
'notification_to' : to_id,
'created_at' : date,
'updated_at' : date,
}
I am able to receive notification but I cannot open the LandingActivity
Please help. Thanks in advance.
FINAL ANSWER
Finally I got it working..I was using android annotations throught my project. The activity which I need to open was also annotated. Hence instead of this line of code
Intent intent = new Intent(this, LandingActivity.class);
i added this
Intent intent = new Intent(this, LandingActivity_.class);
Hope it will be useful for someone at sometime.