Push notifications is not working when the application is open?How does the Java 'for each' loop work?When to use LinkedList over ArrayList in Java?Does Android support near real time push notification?Is quitting an application frowned upon?How do I pass data between Activities in Android application?How can I open a URL in Android's web browser from my application?Android: catching application exitAndroid GCM displaying custom intent when user open notificationHow to handle notification when app in background in FirebaseHow to get particular value from notification remotemessage Android
How does a linear operator act on a bra?
Parallel resistance in electric circuits
How are aircraft depainted?
Why is the Digital 0 not 0V in computer systems?
How do we know that black holes are spinning?
How to write characters doing illogical things in a believable way?
Is there any way to land a rover on the Moon without using any thrusters?
What is this gigantic dish at Ben Gurion airport?
How do I create indestructible terrain?
Some Prime Peerage
What organs or modifications would be needed for a life biological creature not to require sleep?
Is there a real-world mythological counterpart to WoW's "kill your gods for power" theme?
Is a suit against a University Dorm for changing policies on a whim likely to succeed (USA)?
Which is the current decimal separator?
If the gambler's fallacy is false, how do notions of "expected number" of events work?
Telling my mother that I have anorexia without panicking her
What next step can I take in solving this sudoku?
Why the car dealer is insisting on loan instead of cash
Would it be unbalanced to increase Wild Shape uses based on level?
What was the motivation for the invention of electric pianos?
How do certain apps show new notifications when internet access is restricted to them?
Can I conceal an antihero's insanity - and should I?
How to control the output voltage of a solid state relay
Is there a tool to measure the "maturity" of a code in Git?
Push notifications is not working when the application is open?
How does the Java 'for each' loop work?When to use LinkedList over ArrayList in Java?Does Android support near real time push notification?Is quitting an application frowned upon?How do I pass data between Activities in Android application?How can I open a URL in Android's web browser from my application?Android: catching application exitAndroid GCM displaying custom intent when user open notificationHow to handle notification when app in background in FirebaseHow to get particular value from notification remotemessage Android
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to use FCM and the notifications only works when I'm not using the application .
when I send notification from device A to device B , then device B receive the message and "show the notification pop with the default sound" and every thing is good... (this happens when device B is not using the application).
when I send notification from device A to device B , then device B receive the message in the onMessageReceived() method but "does not show the notification pop with the default sound".. (this happens when device B is using the application, I mean when the application is open and is being used).
this is my code
FireIDService.java
public class FireIDService extends FirebaseInstanceIdService
private final String TAG = "FireIDService";
@Override
public void onTokenRefresh()
String tkn = FirebaseInstanceId.getInstance().getToken();
Log.d("Not","Token ["+tkn+"]");
sendRegistrationToServer(tkn);
private void sendRegistrationToServer(String token)
saveDeviceToken(token);
private void saveDeviceToken(String deviceToken)
//some code..
if(response.body().getStatus() == 1)
doStuff();
//some code...
@Override
public void onFailure(Call<SaveDeviceTokenResponse> call, Throwable t)
//code...
);
}
private void doStuff()
Intent intent = new Intent(this, SplashActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1410 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle("FCM Message")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1410 /* ID of notification */, notificationBuilder.build());
}
FireBaseMsgService.java
public class FireBaseMsgService extends FirebaseMessagingService
private final String TAG = "FireBaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage)
super.onMessageReceived(remoteMessage);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "test")
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_background))
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true)
.setColor(0xffff7700)
.setVibrate(new long[]100, 100, 100, 100)
.setPriority(Notification.PRIORITY_MAX)
.setSound(defaultSoundUri);
Intent resultIntent = new Intent(this, SplashActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(SplashActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, notificationBuilder.build());
this is what added to the AndroidManifest.xml file
<service android:name=".FireIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name=".FireBaseMsgService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
and this is the Notify class to be execute
public class Notify extends AsyncTask<Void,Void,Void>
private String tkn;
private String title;
private String body;
public Notify(String tkn, String title, String body)
this.tkn = tkn;
this.title = title;
this.body = body;
@Override
protected Void doInBackground(Void... voids)
Log.e("Token: ", tkn);
Log.e("Title: ", title);
Log.e("Body: ", body);
try
URL url = new URL("https://fcm.googleapis.com/fcm/send");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization","key=KEY_HERE");
conn.setRequestProperty("Content-Type", "application/json");
JSONObject json = new JSONObject();
json.put("to", tkn);
JSONObject info = new JSONObject();
info.put("title", title); // Notification title
info.put("body", body); // Notification body
info.put("priority", "high");
info.put("show_in_foreground", "true");
json.put("notification", info);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(json.toString());
wr.flush();
conn.getInputStream();
catch (Exception e)
Log.d("Error",""+e);
return null;
java android firebase push-notification firebase-cloud-messaging
add a comment
|
I'm trying to use FCM and the notifications only works when I'm not using the application .
when I send notification from device A to device B , then device B receive the message and "show the notification pop with the default sound" and every thing is good... (this happens when device B is not using the application).
when I send notification from device A to device B , then device B receive the message in the onMessageReceived() method but "does not show the notification pop with the default sound".. (this happens when device B is using the application, I mean when the application is open and is being used).
this is my code
FireIDService.java
public class FireIDService extends FirebaseInstanceIdService
private final String TAG = "FireIDService";
@Override
public void onTokenRefresh()
String tkn = FirebaseInstanceId.getInstance().getToken();
Log.d("Not","Token ["+tkn+"]");
sendRegistrationToServer(tkn);
private void sendRegistrationToServer(String token)
saveDeviceToken(token);
private void saveDeviceToken(String deviceToken)
//some code..
if(response.body().getStatus() == 1)
doStuff();
//some code...
@Override
public void onFailure(Call<SaveDeviceTokenResponse> call, Throwable t)
//code...
);
}
private void doStuff()
Intent intent = new Intent(this, SplashActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1410 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle("FCM Message")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1410 /* ID of notification */, notificationBuilder.build());
}
FireBaseMsgService.java
public class FireBaseMsgService extends FirebaseMessagingService
private final String TAG = "FireBaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage)
super.onMessageReceived(remoteMessage);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "test")
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_background))
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true)
.setColor(0xffff7700)
.setVibrate(new long[]100, 100, 100, 100)
.setPriority(Notification.PRIORITY_MAX)
.setSound(defaultSoundUri);
Intent resultIntent = new Intent(this, SplashActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(SplashActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, notificationBuilder.build());
this is what added to the AndroidManifest.xml file
<service android:name=".FireIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name=".FireBaseMsgService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
and this is the Notify class to be execute
public class Notify extends AsyncTask<Void,Void,Void>
private String tkn;
private String title;
private String body;
public Notify(String tkn, String title, String body)
this.tkn = tkn;
this.title = title;
this.body = body;
@Override
protected Void doInBackground(Void... voids)
Log.e("Token: ", tkn);
Log.e("Title: ", title);
Log.e("Body: ", body);
try
URL url = new URL("https://fcm.googleapis.com/fcm/send");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization","key=KEY_HERE");
conn.setRequestProperty("Content-Type", "application/json");
JSONObject json = new JSONObject();
json.put("to", tkn);
JSONObject info = new JSONObject();
info.put("title", title); // Notification title
info.put("body", body); // Notification body
info.put("priority", "high");
info.put("show_in_foreground", "true");
json.put("notification", info);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(json.toString());
wr.flush();
conn.getInputStream();
catch (Exception e)
Log.d("Error",""+e);
return null;
java android firebase push-notification firebase-cloud-messaging
add a comment
|
I'm trying to use FCM and the notifications only works when I'm not using the application .
when I send notification from device A to device B , then device B receive the message and "show the notification pop with the default sound" and every thing is good... (this happens when device B is not using the application).
when I send notification from device A to device B , then device B receive the message in the onMessageReceived() method but "does not show the notification pop with the default sound".. (this happens when device B is using the application, I mean when the application is open and is being used).
this is my code
FireIDService.java
public class FireIDService extends FirebaseInstanceIdService
private final String TAG = "FireIDService";
@Override
public void onTokenRefresh()
String tkn = FirebaseInstanceId.getInstance().getToken();
Log.d("Not","Token ["+tkn+"]");
sendRegistrationToServer(tkn);
private void sendRegistrationToServer(String token)
saveDeviceToken(token);
private void saveDeviceToken(String deviceToken)
//some code..
if(response.body().getStatus() == 1)
doStuff();
//some code...
@Override
public void onFailure(Call<SaveDeviceTokenResponse> call, Throwable t)
//code...
);
}
private void doStuff()
Intent intent = new Intent(this, SplashActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1410 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle("FCM Message")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1410 /* ID of notification */, notificationBuilder.build());
}
FireBaseMsgService.java
public class FireBaseMsgService extends FirebaseMessagingService
private final String TAG = "FireBaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage)
super.onMessageReceived(remoteMessage);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "test")
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_background))
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true)
.setColor(0xffff7700)
.setVibrate(new long[]100, 100, 100, 100)
.setPriority(Notification.PRIORITY_MAX)
.setSound(defaultSoundUri);
Intent resultIntent = new Intent(this, SplashActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(SplashActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, notificationBuilder.build());
this is what added to the AndroidManifest.xml file
<service android:name=".FireIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name=".FireBaseMsgService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
and this is the Notify class to be execute
public class Notify extends AsyncTask<Void,Void,Void>
private String tkn;
private String title;
private String body;
public Notify(String tkn, String title, String body)
this.tkn = tkn;
this.title = title;
this.body = body;
@Override
protected Void doInBackground(Void... voids)
Log.e("Token: ", tkn);
Log.e("Title: ", title);
Log.e("Body: ", body);
try
URL url = new URL("https://fcm.googleapis.com/fcm/send");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization","key=KEY_HERE");
conn.setRequestProperty("Content-Type", "application/json");
JSONObject json = new JSONObject();
json.put("to", tkn);
JSONObject info = new JSONObject();
info.put("title", title); // Notification title
info.put("body", body); // Notification body
info.put("priority", "high");
info.put("show_in_foreground", "true");
json.put("notification", info);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(json.toString());
wr.flush();
conn.getInputStream();
catch (Exception e)
Log.d("Error",""+e);
return null;
java android firebase push-notification firebase-cloud-messaging
I'm trying to use FCM and the notifications only works when I'm not using the application .
when I send notification from device A to device B , then device B receive the message and "show the notification pop with the default sound" and every thing is good... (this happens when device B is not using the application).
when I send notification from device A to device B , then device B receive the message in the onMessageReceived() method but "does not show the notification pop with the default sound".. (this happens when device B is using the application, I mean when the application is open and is being used).
this is my code
FireIDService.java
public class FireIDService extends FirebaseInstanceIdService
private final String TAG = "FireIDService";
@Override
public void onTokenRefresh()
String tkn = FirebaseInstanceId.getInstance().getToken();
Log.d("Not","Token ["+tkn+"]");
sendRegistrationToServer(tkn);
private void sendRegistrationToServer(String token)
saveDeviceToken(token);
private void saveDeviceToken(String deviceToken)
//some code..
if(response.body().getStatus() == 1)
doStuff();
//some code...
@Override
public void onFailure(Call<SaveDeviceTokenResponse> call, Throwable t)
//code...
);
}
private void doStuff()
Intent intent = new Intent(this, SplashActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1410 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle("FCM Message")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1410 /* ID of notification */, notificationBuilder.build());
}
FireBaseMsgService.java
public class FireBaseMsgService extends FirebaseMessagingService
private final String TAG = "FireBaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage)
super.onMessageReceived(remoteMessage);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "test")
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_background))
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true)
.setColor(0xffff7700)
.setVibrate(new long[]100, 100, 100, 100)
.setPriority(Notification.PRIORITY_MAX)
.setSound(defaultSoundUri);
Intent resultIntent = new Intent(this, SplashActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(SplashActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
notificationBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, notificationBuilder.build());
this is what added to the AndroidManifest.xml file
<service android:name=".FireIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name=".FireBaseMsgService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
and this is the Notify class to be execute
public class Notify extends AsyncTask<Void,Void,Void>
private String tkn;
private String title;
private String body;
public Notify(String tkn, String title, String body)
this.tkn = tkn;
this.title = title;
this.body = body;
@Override
protected Void doInBackground(Void... voids)
Log.e("Token: ", tkn);
Log.e("Title: ", title);
Log.e("Body: ", body);
try
URL url = new URL("https://fcm.googleapis.com/fcm/send");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization","key=KEY_HERE");
conn.setRequestProperty("Content-Type", "application/json");
JSONObject json = new JSONObject();
json.put("to", tkn);
JSONObject info = new JSONObject();
info.put("title", title); // Notification title
info.put("body", body); // Notification body
info.put("priority", "high");
info.put("show_in_foreground", "true");
json.put("notification", info);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(json.toString());
wr.flush();
conn.getInputStream();
catch (Exception e)
Log.d("Error",""+e);
return null;
java android firebase push-notification firebase-cloud-messaging
java android firebase push-notification firebase-cloud-messaging
edited Mar 28 at 13:41
Frank van Puffelen
275k37 gold badges448 silver badges468 bronze badges
275k37 gold badges448 silver badges468 bronze badges
asked Mar 28 at 10:43
Mohammed DarwishMohammed Darwish
203 bronze badges
203 bronze badges
add a comment
|
add a comment
|
1 Answer
1
active
oldest
votes
If you are using android 8.0+. You need to specify channelId for notification.
When your app is in background (as mention in your first case), the push notification is recieved in system notification tray, rather than your FireBaseMsgService, and it is handled automatically by the system by channelId is genreated by system itself.
When your app is in foreground (second case) your FireBaseMsgService is executed and have to create notification channelId
your answer seems to be right , but could you please tell where and under what condition should I add this notification channel , what might be the code look like in my case ! could you please help with that ?
– Mohammed Darwish
Mar 28 at 12:36
Notification channel is used in android 8.0 later. developer.android.com/training/notify-user/…
– Saurav Kumar
Mar 28 at 12:45
Thanks Saurav Kumar , Your answer was exactly what I'm looking for , It, works perfect now , the message arrived in both cases .
– Mohammed Darwish
Mar 28 at 14:19
Glad you liked.
– Saurav Kumar
Mar 28 at 14:22
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395594%2fpush-notifications-is-not-working-when-the-application-is-open%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you are using android 8.0+. You need to specify channelId for notification.
When your app is in background (as mention in your first case), the push notification is recieved in system notification tray, rather than your FireBaseMsgService, and it is handled automatically by the system by channelId is genreated by system itself.
When your app is in foreground (second case) your FireBaseMsgService is executed and have to create notification channelId
your answer seems to be right , but could you please tell where and under what condition should I add this notification channel , what might be the code look like in my case ! could you please help with that ?
– Mohammed Darwish
Mar 28 at 12:36
Notification channel is used in android 8.0 later. developer.android.com/training/notify-user/…
– Saurav Kumar
Mar 28 at 12:45
Thanks Saurav Kumar , Your answer was exactly what I'm looking for , It, works perfect now , the message arrived in both cases .
– Mohammed Darwish
Mar 28 at 14:19
Glad you liked.
– Saurav Kumar
Mar 28 at 14:22
add a comment
|
If you are using android 8.0+. You need to specify channelId for notification.
When your app is in background (as mention in your first case), the push notification is recieved in system notification tray, rather than your FireBaseMsgService, and it is handled automatically by the system by channelId is genreated by system itself.
When your app is in foreground (second case) your FireBaseMsgService is executed and have to create notification channelId
your answer seems to be right , but could you please tell where and under what condition should I add this notification channel , what might be the code look like in my case ! could you please help with that ?
– Mohammed Darwish
Mar 28 at 12:36
Notification channel is used in android 8.0 later. developer.android.com/training/notify-user/…
– Saurav Kumar
Mar 28 at 12:45
Thanks Saurav Kumar , Your answer was exactly what I'm looking for , It, works perfect now , the message arrived in both cases .
– Mohammed Darwish
Mar 28 at 14:19
Glad you liked.
– Saurav Kumar
Mar 28 at 14:22
add a comment
|
If you are using android 8.0+. You need to specify channelId for notification.
When your app is in background (as mention in your first case), the push notification is recieved in system notification tray, rather than your FireBaseMsgService, and it is handled automatically by the system by channelId is genreated by system itself.
When your app is in foreground (second case) your FireBaseMsgService is executed and have to create notification channelId
If you are using android 8.0+. You need to specify channelId for notification.
When your app is in background (as mention in your first case), the push notification is recieved in system notification tray, rather than your FireBaseMsgService, and it is handled automatically by the system by channelId is genreated by system itself.
When your app is in foreground (second case) your FireBaseMsgService is executed and have to create notification channelId
answered Mar 28 at 12:11
Saurav KumarSaurav Kumar
1347 bronze badges
1347 bronze badges
your answer seems to be right , but could you please tell where and under what condition should I add this notification channel , what might be the code look like in my case ! could you please help with that ?
– Mohammed Darwish
Mar 28 at 12:36
Notification channel is used in android 8.0 later. developer.android.com/training/notify-user/…
– Saurav Kumar
Mar 28 at 12:45
Thanks Saurav Kumar , Your answer was exactly what I'm looking for , It, works perfect now , the message arrived in both cases .
– Mohammed Darwish
Mar 28 at 14:19
Glad you liked.
– Saurav Kumar
Mar 28 at 14:22
add a comment
|
your answer seems to be right , but could you please tell where and under what condition should I add this notification channel , what might be the code look like in my case ! could you please help with that ?
– Mohammed Darwish
Mar 28 at 12:36
Notification channel is used in android 8.0 later. developer.android.com/training/notify-user/…
– Saurav Kumar
Mar 28 at 12:45
Thanks Saurav Kumar , Your answer was exactly what I'm looking for , It, works perfect now , the message arrived in both cases .
– Mohammed Darwish
Mar 28 at 14:19
Glad you liked.
– Saurav Kumar
Mar 28 at 14:22
your answer seems to be right , but could you please tell where and under what condition should I add this notification channel , what might be the code look like in my case ! could you please help with that ?
– Mohammed Darwish
Mar 28 at 12:36
your answer seems to be right , but could you please tell where and under what condition should I add this notification channel , what might be the code look like in my case ! could you please help with that ?
– Mohammed Darwish
Mar 28 at 12:36
Notification channel is used in android 8.0 later. developer.android.com/training/notify-user/…
– Saurav Kumar
Mar 28 at 12:45
Notification channel is used in android 8.0 later. developer.android.com/training/notify-user/…
– Saurav Kumar
Mar 28 at 12:45
Thanks Saurav Kumar , Your answer was exactly what I'm looking for , It, works perfect now , the message arrived in both cases .
– Mohammed Darwish
Mar 28 at 14:19
Thanks Saurav Kumar , Your answer was exactly what I'm looking for , It, works perfect now , the message arrived in both cases .
– Mohammed Darwish
Mar 28 at 14:19
Glad you liked.
– Saurav Kumar
Mar 28 at 14:22
Glad you liked.
– Saurav Kumar
Mar 28 at 14:22
add a comment
|
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395594%2fpush-notifications-is-not-working-when-the-application-is-open%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown