I have to show push notification while user is logged in.So when app opens am taking deviceToken.So it will register to server always.But when user logout i dont want to show push notification.So how can i do it?
Now i have done with checking preference value like the below code,
public void onMessageReceived(String from, Bundle data) {
loginPref = getSharedPreferences("loginPreference", Context.MODE_PRIVATE);
mEditPrefs = loginPref.edit();
userID = loginPref.getString("userId", null);
if(userID!=null){
Bundle bundle = data.getBundle("notification");
Log.d("Bundle123::", bundle + "");
if (bundle != null) {
String text = bundle.getString("text");
String body = bundle.getString("body");
String title = bundle.getString("title");
Log.d("text123::", text + "");
Log.d("title123::", title + "");
Intent in = new Intent();
in.setAction("GCM_RECEIVED");
sendBroadcast(in);
sendNotification(title,body);
}
}
But when app backgrounds this condition doesn't work.How can i do it?Because i cant delete the token because when am trying login i have to send device token too..