Pass the content intent for notification builder using the below method
private PendingIntent getEmptyPendingIntent(Context context) {
Intent resultIntent = new Intent(context, InitializationActivity.class);
resultIntent.setAction(Long.toString(System.currentTimeMillis())); //adding unique identification for each intent
resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(InitializationActivity.class);
stackBuilder.addNextIntent(resultIntent);
stackBuilder.getIntentCount();
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
return resultPendingIntent;
}
Send the notification using the below method
private void sendNotification(String title, String message) {
Intent intent = new Intent(this, InitializationActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
String desc = "";
if (!TextUtils.isEmpty(message)) {
try {
JSONObject jsonObject = new JSONObject(message);
desc = jsonObject.optString("payload");
} catch (JSONException e) {
e.printStackTrace();
}
}
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 , intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)getResources().getDrawable(R.drawable.notify_large)).getBitmap())
.setContentTitle(title)
.setContentText(desc)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(getEmptyPendingIntent(this));
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}