aarav aarav - 2 months ago 8
Android Question

When user logged out and the push notification come my app opens automatically. i want to open my app on the click of push notification?

This is the method by which i am sending the push notification :-

private void sendNotification(String msg) {

mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent;
Intent intentblank = new Intent(this, LoginActivity.class);
intentblank.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentblank);


Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

Log.e("message.....", msg);


if (msg.equals("You Have got New Message")) {

Log.e("msg occuring..", "intent enter in message...");
intent.putExtra("KEYMESSAGE", "Message");

} else {

Log.e("notification occuring..", "notification occurs.....");
intent.putExtra("KEYNOTIFICATION", "aman");


}



if (sharedPreferencesUtilities.getEmail().equals("") || sharedPreferencesUtilities.getPassword().equals("")) {
Log.e("blank notification....", "blank notification...........................");
contentIntent =PendingIntent.getActivity(this, 0, intentblank, 0);
} else {
contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}


mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(getNotificationIcon())
.setContentTitle("Telepoh")
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText(msg)
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);

mBuilder.setContentIntent(contentIntent);
mBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
mBuilder.getNotification().flags |= Notification.FLAG_ONGOING_EVENT;
mBuilder.setOngoing(false);

mBuilder.setAutoCancel(true);


mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());


}

private int getNotificationIcon() {
boolean useWhiteIcon = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
return useWhiteIcon ? R.drawable.push_icon : R.drawable.push_icon;
}
}


I want that when the user logged out then on the click on the push notification the login page is open of my app. but in my case if the user logged out then the app is open automaticaly. i want to do it on the click of the push notification.if anyone have any idea. so please tell me. its urgent.

Answer

remove below line of code

 startActivity(intentblank);