Coder Social home page Coder Social logo

Comments (143)

thedumbtechguy avatar thedumbtechguy commented on May 19, 2024 83

@samtstern Both comments are incorrect.

Custom messaging service is only called when the app is in the foreground.

Android does not turn the icon white. It keeps its color.

I've already implemented FirebaseMessagingService for my app when it's in the foreground.
What we are asking for is how to handle it when it's in the background.

I don't understand why the notification is created automatically when FCM is meant to replace GCM. It is totally incompatible with the current flow.

from quickstart-android.

ckarthikv avatar ckarthikv commented on May 19, 2024 37

@samtstern - Yes, we wanted to implement custom notification styles like Big Picture style, etc, when the app is in background or when the app is killed. I believe the notifications would be working through a broadcast receiver?

Would be great if you could point me in the right direction so that one could intercept all kinds of messages (probably by extending the FirebaseBroadcastReceiver class) - whether the app is in background or killed, so that we could customize every aspect of the notification styles immaterial of the app state.

from quickstart-android.

samtstern avatar samtstern commented on May 19, 2024 27

As far as I am aware it is not possible to customize the icon through the
console right now, but that is a high-priority feature for us going forward.

On Tue, May 24, 2016 at 12:48 PM Artem Osipov [email protected]
wrote:

@samtstern https://github.com/samtstern thank you for the doc link,
really helpfull.

Console has custom params when sending a message,
must the custom icon work there too? ( In my test this is still the app
icon, but I can do something wrong)


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#4 (comment)

from quickstart-android.

samtstern avatar samtstern commented on May 19, 2024 25

@frostymarvelous the behavior you are seeing sounds like a bug, in my apps the FirebaseMessagingService is definitely called when the app is in the background.

As far as the icon color, on recent versions of Android the system applies a white mask to the icon. What sort of device do you have and what version of Android is it running?

from quickstart-android.

thedumbtechguy avatar thedumbtechguy commented on May 19, 2024 24

An S6 running 5.1.1.

I think your behavior is the bug.

From the docs

"When your app is in the background on a user's device, notifications are
delivered to the system tray. When a user clicks on the notification, the
app launcher opens your app. If you want, you can also add client message
handling to receive notifications in your app when it is already in the
foreground on the user's device."

On Fri, May 20, 2016, 7:29 PM Sam Stern [email protected] wrote:

@frostymarvelous https://github.com/frostymarvelous the behavior you
are seeing sounds like a bug, in my apps the FirebaseMessagingService is
definitely called when the app is in the background.

As far as the icon color, on recent versions of Android the system applies
a white mask to the icon. What sort of device do you have and what version
of Android is it running?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#4 (comment)

from quickstart-android.

pinkeshdarji avatar pinkeshdarji commented on May 19, 2024 23

I am developing movie review app where I need to push a message with movie title and movie poster so for that I need to implement NotificationCompat.BigPictureStyle regardless of app state(Foreground /Background) BUT i found that this could not happen when app is in the background with firebase cloud messaging.

There must be some mechanism like this:
public void onMessageReceived(RemoteMessage remoteMessage) {
// Determine app state (foreground/background)
// if(foreground){
// use notification style 1
//}
//else(){
// use notification style 2
// }
}

After reading entire page I have decided NOT to use firebase as of now, I will implement GCM again. I hope this gets resolved as soon as possible.I am big fan of firebase.

from quickstart-android.

shinayser avatar shinayser commented on May 19, 2024 23

Just want to leave my feedback about the notification framework:
We as developers should have full control of the notifications. I never wanted FCM to auto-notify my system bar for me and i should ALWAYS receive the "onMessageReceived" callback, doesn't matter in foreground or background.

Pehaps we could have a checkbox on the Firebase Notification console indicating "Auto-notify". If unchecked, we get the "onMessageReceived" callback. Otherwise, it notifies the system bar.

from quickstart-android.

thedumbtechguy avatar thedumbtechguy commented on May 19, 2024 18

Same problem. The icon being used is not what I want.
It is using the launcher icon while but the new guidelines require that we use a white on transparent icon. Also, the color is wrong.
I can't seem to find any way to customize this looking at the available methods.

Any help?

from quickstart-android.

thedumbtechguy avatar thedumbtechguy commented on May 19, 2024 15

I'd prefer we simply got the opportunity to handle all notifications if
possible like we did with GCM.
It can be a configuration item as well.

I'm currently not using FCM to push notifications due to it being
unpredictable atm.

On Fri, May 27, 2016 at 9:24 AM, Artem Osipov [email protected]
wrote:

@sir-gon https://github.com/sir-gon if you don't specify the custom
icon, FCM will use the app icon.
I'm agree, if we can just set the default icon in some settings file, it'd
be more convenient.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#4 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AA4XZcaeLgZSGWEWC7nuNovN3nQiTZswks5qFrhWgaJpZM4IiXTl
.

Regards,
Stefan Froelich.

from quickstart-android.

yayaa avatar yayaa commented on May 19, 2024 11

Sending notifications from console is really powerful feature thanks for that, but since it is not possible to customize notifications when application is in background, as @frostymarvelous said would it be possible to create a configuration item or something like that and handle it in FCM? And maybe we could have previews of notification how would it be seen on devices?

Setting a bigImage, defining action buttons, small icon, and even wear optimisations... by this configuration item.

Then it would be an amazing feature to use, but right now it forces not to use :(
(Because you know customer NEVER gets enough with default behaviours and they ALWAYS need custom stuff :))

from quickstart-android.

samtstern avatar samtstern commented on May 19, 2024 7

Sorry @frostymarvelous I misunderstood your situation, you are correct. When you send a notification from the Firebase console and your app is in the background it cannot be customized.

If you want custom background notifications you should use the FCM API to send data messages to your app and handle them in the FirebaseMessagingService where you can decide how the notification should look.

from quickstart-android.

Svoka avatar Svoka commented on May 19, 2024 6

@DespisedIcon I had the similar problem, but it was my mistake I set it in the data section and it must be in the notification.
Like this:

'to' => '_PHONE_ID_', "notification"=>array( 'title'=>"Test", 'body'=>"Test2", "icon"=>"ic_stat_ic_notification" // R.drawable.ic_stat_ic_notification )

from quickstart-android.

2ndGAB avatar 2ndGAB commented on May 19, 2024 6

@abdymalikmulky ok so if I understand well, when the application is in background, the Notification is received by the system tray and not your application.
I never tried it so I cannot help you about the problem you have with your icon. I'm really sorry.

I'm not so experienced with FCM but the basics are the following.

When your application is in foreground, the notification and the data payload is received by onMessageReceive() as you do.
When the applicaton is in background, there are 2 situations:

  • You send a Notification only message and it's received in the system tray and displayed as you observe but your application is not informed about it.
  • You send a Notification with a data payload like you do and the behavior is the one explained just above except that the data payload is passed to your application via the Intent you receive in your main activity when the user tap the notification which cause your app to be started.

But if you have time, I would be very interested that you try to create your notification in your application, based on data message only.
That suppose to send the message from Google Advanced REST Client Google Advanced REST Client

Then you receive the data payload in onMessageReceive() as you certainly do already and you generate your notification from onMessageReceive() as you may do already but in case and just for a very simple test:

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    Log.d(TAG, "From: " + remoteMessage.getFrom());
    Log.d(TAG, "Notification Message Body: " + remoteMessage.getData());

    sendNotification("FCM message received");

}

private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    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.drawable.ic_stat_ic_notification)
            .setContentTitle("FCM Message")
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0, notificationBuilder.build());
}

I would be very interested to know if a notification is created when you send the message while the application is in background.
ic_stat_ic_notification (drawable hdpi)

ic_stat_ic_notification is attached.

from quickstart-android.

xo0ps avatar xo0ps commented on May 19, 2024 4

I have the same problem. I need to store notification in db for late use and also change the notification style and couple of more works on the received notification which is not possible. Please fix this issue as soon as possible.

from quickstart-android.

shinayser avatar shinayser commented on May 19, 2024 4

@Svoka No, I did not. When in background, the Firebase Notifications (in Console) doesn't have data-only notifications. So, we can't customize it when app is in background.

from quickstart-android.

kroikie avatar kroikie commented on May 19, 2024 3

@DespisedIcon could you add your http request here maybe there is an issue with the formatting.

from quickstart-android.

yishai-glide avatar yishai-glide commented on May 19, 2024 3

Agreed

On Thu, Jul 14, 2016, 18:43 shinayser [email protected] wrote:

Just want to leave my feedback about the notification framework:
We as developers should have full control of the notifications. I never
wanted FCM to auto-notify my system bar for me and i should ALWAYS receive
the "onMessageReceived" callback, doesn't matter in foreground or
background.

Pehaps we could have a checkbox on the Firebase Notification console
indicating "Auto-notify". If unchecked, we get the "onMessageReceived"
callback. Otherwise, it notifies the system bar.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#4 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ACtEJrpZWE717XEPnLr1NxigCL6Mly-cks5qVlk9gaJpZM4IiXTl
.

Have a nice day
Yishai Levenglick
Android developer
+972-54-520-9569

from quickstart-android.

samtstern avatar samtstern commented on May 19, 2024 2

@ckarthikv you can see this example of FirebaseMessagingService which is where your app can receive FCM messages and react. This is a good place to create notifications.

Telling if your Activity is in the foreground (and reacting differently) can be a little tricky. My favorite way is to register a local BroadcastReceiver in the Activity and then do a sendBroadcast from the service. You will get true from that method if your receiver is running (meaning your app is in the foreground), and false otherwise.

You can see an example of this (using GCM, but the logic is the same for FCM) here.

from quickstart-android.

AndreasZeiser avatar AndreasZeiser commented on May 19, 2024 2

@kroikie Can you please clarify when we can expect a fix? Sending notifications through the Firebase console was the main reason for us to jump on the Firebase train.

Also, I want to point out that I'm not able to fully customize a notification inside onMessageReceived callback. What I do is simple: build a notification with NotificationCompat with title, body and a small icon from my drawables. When the notification gets shown, the icon is transparent. If I use the launcher icon instead it shows up as expected.

from quickstart-android.

yayaa avatar yayaa commented on May 19, 2024 2

Since i am not able to create a custom notification -as talked above- we decided to implement data-only messages via FCM API, and not use console -even though how powerful it is.

But just out of curiosity is there a way that FCM console messages displayed by using colorPrimary | colorAccent or any of resources? And also if the notification gets icon from R.mipmap.ic_launcher or it gets icon from application's icon?

Because i can't know how that automated notification is built, i just wanted to know if there is any resources that build configuration is currently getting data from? So that i may try a work around on those values to get a good look in case of we consider send notification from console in future.
(Right now we do not even mention about it, because it displays a notification with gray background and a white rounded square icon)

from quickstart-android.

abdymm avatar abdymm commented on May 19, 2024 2

@2ndGAB i have created my onMessageReceive() , that method just call when app in foreground
this is my screenshoot

foreground notification (notification that i want)
photo264167697778059618

background notification

  1. Just show the white background icon (even though my color parameter is works)
  2. not showing notification like in foreground
    photo264167697778059620

photo264167697778059619

i just confuse of FCM behavior , Would be very helpful. Thanks.

from quickstart-android.

Svoka avatar Svoka commented on May 19, 2024 1

@samtstern I can't find an example of FCM API and how to manage the custom icon.
Do you have an example of this? I'm new to cloud messaging and I only find that there is a parameter icon, but no details how to implement it in my app
Thank you!

from quickstart-android.

samtstern avatar samtstern commented on May 19, 2024 1

Here is the documentation for sending Notification messages.

The icon parameter can be used to specify a drawable within your app. If you want to use R.drawable.foo, just pass foo.

from quickstart-android.

antoineF avatar antoineF commented on May 19, 2024 1

The problem of using data notification instead of notification message is that it is not compatible with iOS. For exemple, if you want to send a message to a topic to both iOS and Android it's hard to find way to be compatible to the both platforms :
Send only data payloads -> message is not sent to iOS,
Send notification payloads (with or without data payloads) -> white icon on android.

The tip of @Svoka solves the bug for now, but it's quite a hack!...

from quickstart-android.

pinkeshdarji avatar pinkeshdarji commented on May 19, 2024 1

Thanks @kroikie,
onMessageReceived being called whether the app is in the foreground or the background by just passing data only messages as you suggested.

Now I can handle data like this-
public void onMessageReceived(RemoteMessage remoteMessage) {
String topic = remoteMessage.getFrom();
String movieId = remoteMessage.getData().get("movieId");
String title = remoteMessage.getData().get("title");
String details = remoteMessage.getData().get("details");
String movieUrl = remoteMessage.getData().get("movieUrl");

    sendNotification(movieId,title,details,movieUrl);

}

In sendNotification I can create custom notification.
Thanks Once again.

from quickstart-android.

 avatar commented on May 19, 2024 1

Can anyone please provide some example how can i use the api to send data only messages (php), currently i am using console to send notification and data, but it acts differently when app is in background or foreground..

from quickstart-android.

Svoka avatar Svoka commented on May 19, 2024 1

@xainbutt it's really simple, you can adapt the following code:

`$toWhom = '';
$serverKey = '';
$serverFrom = '';

// The data to send to the API
$postData = array(
'to' => $toWhom,
"notification"=>array(
'title'=>"Test",
'body'=>"Test2",
"icon"=>"ic_stat_ic_notification"
)
);

// Setup cURL
$ch = curl_init('https://fcm.googleapis.com/fcm/send');
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_HTTPHEADER => array(
'Authorization:key='.$serverKey,
'Content-Type: application/json'
),
CURLOPT_POSTFIELDS => json_encode($postData)
));

// Send the request
$response = curl_exec($ch);

// Check for errors
if($response === FALSE){
die(curl_error($ch));
}

print '

' . print_r($response, true) . '
';`

from quickstart-android.

Svoka avatar Svoka commented on May 19, 2024 1

@xainbutt yes, you're right. This code needs to to do a little modification if you want to send data-messages.

from quickstart-android.

KishorFlutter avatar KishorFlutter commented on May 19, 2024 1

Is it possible to use GCM receiver and FirebaseMessagingService's onMessageReceived(RemoteMessage remoteMessage){..} both at the same time.

It appears to me that when I send notification from Firbase console and app is in background... in my code both GCM receiver and FCM notification is showed.

from quickstart-android.

KishorFlutter avatar KishorFlutter commented on May 19, 2024 1

@abdymalikmulky yes... When App is in background firebase shows default notification as per documentaion.

In my code I have kept both GCM receiver and FirebaseMessagingService. My problem is when I send message from firebase console it invokes GCM receiver as well as Firebase notification.

from quickstart-android.

samtstern avatar samtstern commented on May 19, 2024

@ckarthikv could you clarify this question a little bit? Are you trying to show different notification styles when your app is in the background versus when your app is running in the foreground?

from quickstart-android.

ashokmachineni avatar ashokmachineni commented on May 19, 2024

Hi,
When i tried to implement this notification i get error like
Error:(28, 0) Plugin with id 'com.google.gms.google-services' not found.

from quickstart-android.

samtstern avatar samtstern commented on May 19, 2024

@frostymarvelous when you send a notification from the Firebase console is uses your app icon by default, and the Android system will turn that icon solid white when in the notification bar.

If you are unhappy with that result you should implement FirebaseMessagingService and create the notifications manually when you receive a message. We are working on a way to improve this but for now that's the only way.

from quickstart-android.

thedumbtechguy avatar thedumbtechguy commented on May 19, 2024

If that works, then I'm good.
I thought it behaved the same across.

Thanks a lot for your help.
If you're part of the team, then thanks for your hard work as well.

On Fri, May 20, 2016, 8:30 PM Sam Stern [email protected] wrote:

Sorry @frostymarvelous https://github.com/frostymarvelous I
misunderstood your situation, you are correct. When you send a notification from
the Firebase console
and your app is in the background it cannot be
customized.

If you want custom background notifications you should use the FCM API to
send data messages to your app and handle them in the
FirebaseMessagingService where you can decide how the notification should
look.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#4 (comment)

from quickstart-android.

samtstern avatar samtstern commented on May 19, 2024

@frostymarvelous ok thanks for your patience while I figured out what was going on.

Please feel free to open issues if you try this approach and have questions. Good luck!

from quickstart-android.

Svoka avatar Svoka commented on May 19, 2024

@samtstern thank you for the doc link, really helpfull.

Console has custom params when sending a message,
must the custom icon work there too? ( In my test this is still the app icon, but I can do something wrong)

from quickstart-android.

thedumbtechguy avatar thedumbtechguy commented on May 19, 2024

It will only work if your app is in the foreground. Otherwise, you have to
use the the api.

On Tue, May 24, 2016, 7:48 PM Artem Osipov [email protected] wrote:

@samtstern https://github.com/samtstern thank you for the doc link,
really helpfull.

Console has custom params when sending a message,
must the custom icon work there too? ( In my test this is still the app
icon, but I can do something wrong)


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#4 (comment)

from quickstart-android.

kroikie avatar kroikie commented on May 19, 2024

The key value pairs currently available in the Firebase composer are for data message values only.

from quickstart-android.

thedumbtechguy avatar thedumbtechguy commented on May 19, 2024

Do we need to customize it through console? Can't we just add it as a
config parameter? Thanks would be better
Don't forget the colors as well please?

Once again, thanks for the great job you all are doing!

On Tue, May 24, 2016, 8:47 PM Sam Stern [email protected] wrote:

As far as I am aware it is not possible to customize the icon through the
console right now, but that is a high-priority feature for us going
forward.

On Tue, May 24, 2016 at 12:48 PM Artem Osipov [email protected]
wrote:

@samtstern https://github.com/samtstern thank you for the doc link,
really helpfull.

Console has custom params when sending a message,
must the custom icon work there too? ( In my test this is still the app
icon, but I can do something wrong)


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
<
#4 (comment)


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#4 (comment)

from quickstart-android.

kroikie avatar kroikie commented on May 19, 2024

It would have to be through the console since the client side handler does not reference any of your specified remote config parameters.

from quickstart-android.

thedumbtechguy avatar thedumbtechguy commented on May 19, 2024

Well, I thought that would work through the Configuration in the
Application class. I wonder how that would work since we can't tell the
value of whatever R.drawable.foo will be.

On Tue, May 24, 2016, 9:51 PM Arthur Thompson [email protected]
wrote:

It would have to be through the console since the client side handler does
not reference any of your specified remote config parameters.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#4 (comment)

from quickstart-android.

bosbefok avatar bosbefok commented on May 19, 2024

I'm having a similar issue getting the notifications customized. I'm not using the console at all - only making API calls. When app is in foreground notifications get handled by my custom FirebaseMessagingService, but when app is in the background notification displays solid white icon and ignores any specified payload support parameters (icon, color etc).

Please advise whether this is expected as the behaviour appears to contradict comments made in this thread as well as #8

from quickstart-android.

bosbefok avatar bosbefok commented on May 19, 2024

@Svoka Thanks for the tip. I've moved the icon parameter into the notification and now I'm getting the message

W/FirebaseMessaging: Icon resource icon ic_stat_logo not found. Notification will use app icon.

This same icon (R.drawable.ic_stat_logo) is being used for foreground notification builder without any issues.

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_logo)
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))

Any idea why Firebase cannot resolve the icon for background notification?

from quickstart-android.

bosbefok avatar bosbefok commented on May 19, 2024

@kroikie You were right. I've tracked down this issue to malformed notification data in the request. Icon and color working correctly now. Thanks

from quickstart-android.

sir-gon avatar sir-gon commented on May 19, 2024

@Svoka thats work form me... but only for small icon... any idea for large icon?
(This method is not the desired way... y don't need to send a custom "icon" parameter for iOS)

from quickstart-android.

Svoka avatar Svoka commented on May 19, 2024

@sir-gon if you don't specify the custom icon, FCM will use the app icon.
I'm agree, if we can just set the default icon in some settings file, it'd be more convenient.

from quickstart-android.

Svoka avatar Svoka commented on May 19, 2024

@frostymarvelous but when app in background GCM also send it to notification tray, not in app.

from quickstart-android.

kroikie avatar kroikie commented on May 19, 2024

@frostymarvelous to be clear @Svoka is correct, FCM handles messages in the exact same way as GCM. Notification messages have always been handled in this way. If you always want to handle all notifications then you should send data only messages and handle the creation and display of notifications yourself. Note however that messages from the Firebase console are notification messages.

from quickstart-android.

thedumbtechguy avatar thedumbtechguy commented on May 19, 2024

Thanks for clarifying that. Again.
I will give it another spin this weekend!

from quickstart-android.

kroikie avatar kroikie commented on May 19, 2024

@antoineF thanks for the feedback however:

  • Data only payloads can be sent to iOS, see the content_available field in the reference docs. Also when the iOS app is connected to FCM (in the foreground) data messages are sent through the FCM connection and through APNs otherwise.
  • The white icon on Android is a known issue, the FCM team is working on a fix.

from quickstart-android.

kroikie avatar kroikie commented on May 19, 2024

Thanks for the feedback @yayaa it is noted!

from quickstart-android.

thedumbtechguy avatar thedumbtechguy commented on May 19, 2024

Couldn't have said it better myself.
The dashboard is a really powerful tool and I'm currently not even attempting to use it.

from quickstart-android.

SplinterII avatar SplinterII commented on May 19, 2024

I'm still such a noob, but via Raspberry Pi, Node-red and Firebase I now receive a notification on my phone when someone presses my doorbell. Helped by this page, even when the notification sample app is in the background, I get vibs or a tone. What I prefer though is, when the app is in the background and someone presses my doorbell I get a continuing ringtone, just like when someone would call me. This would be 'easy' when the app is in the foreground, but how to do it when it's in the background? From reading above I believe this cant be done yet, right?

from quickstart-android.

kroikie avatar kroikie commented on May 19, 2024

@AndreasZeiser While I'm not able to give you a date for the fix to the icon issue, I can say that this is a high priority for the FCM team, and a solution will be released ASAP. I'm not sure why your notification icon is coming up transparent, once you receive the onMessageReceived callback you should be able to create and show notifications in the standard way, using NotificationCompat like you are.

@pinkeshdarji It may be worth noting that FCM and GCM receive notification messages the same way. So the foreground/background logic (which only applies to notification messages) will apply whether you are using FCM or GCM. I think that using FCM with data only messages will accomplish what you want since data only messages result in onMessageReceived being called whether the app is in the foreground or the background. The app being in the foreground or the background is only an issue when sending/receiving notification messages.

@NL-Splinter In cases when you want to have a callback to onMessageReceived whether the app is in the foreground or background then you should send data only messages.

from quickstart-android.

SplinterII avatar SplinterII commented on May 19, 2024

Hi Arthur,

Thanks to your comment I now understand how to send a data only message, and the example app is indeed responding accordingly.

The only thing I don’t understand is:

the data payload is delivered in the extras of the intent of your launcher Activity

This kind of language is beyond my current Android skills :(

And this is not the way right? (I’m getting null as a msg)

private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
Log.d(TAG, "Msg: " + intent.getStringExtra("score"));

In other words: where and how do I pick up the (key/)value pair sent via the data?

I’m guessing it’s just 1 line of code, which I hope isn’t too much asked.

Thanks anyway for your help sofar!!

Regards, Jan

Van: Arthur Thompson [mailto:[email protected]]
Verzonden: woensdag 1 juni 2016 22:26
Aan: firebase/quickstart-android [email protected]
CC: NL-Splinter [email protected]; Mention [email protected]
Onderwerp: Re: [firebase/quickstart-android] Custom Notifications when app is in background or killed (#4)

@AndreasZeiser https://github.com/AndreasZeiser While I'm not able to give you a date for the fix to the icon issue, I can say that this is a high priority for the FCM team, and a solution will be released ASAP. I'm not sure why your notification icon is coming up transparent, once you receive the onMessageReceived callback you should be able to create and show notifications in the standard way, using NotificationCompat like you are.

@pinkeshdarji https://github.com/pinkeshdarji It may be worth noting that FCM and GCM receive notification messages the same way. So the foreground/background logic (which only applies to notification messages) will apply whether you are using FCM or GCM. I think that using FCM with data only messages will accomplish what you want since data only messages result in onMessageReceived being called whether the app is in the foreground or the background. The app being in the foreground or the background is only an issue when sending/receiving notification messages.

@NL-Splinter https://github.com/NL-Splinter In cases when you want to have a callback to onMessageReceived whether the app is in the foreground or background then you should send data only messages.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub #4 (comment) , or mute the thread https://github.com/notifications/unsubscribe/AFqfSgm0rzEqP2kVtNeYCpKbQHR05yc-ks5qHeregaJpZM4IiXTl .

from quickstart-android.

SplinterII avatar SplinterII commented on May 19, 2024

Super, helped me a lot!

I'm using this now to get the whole key/value set:

        for (String key : remoteMessage.getData().keySet()) {
            Log.d(TAG, key + ": " + remoteMessage.getData().get(key));
        }

from quickstart-android.

swatijiet avatar swatijiet commented on May 19, 2024

Does data only message means the message text on the top has to remain empty and only key value pairs in advanced options are to be filled? I am still getting a totally white color icon on lollipop and above.

screen shot 2016-06-03 at 7 43 58 am

from quickstart-android.

Svoka avatar Svoka commented on May 19, 2024

@swatijiet you can't send data-only messages from Console at the moment. You need to use API

from quickstart-android.

gauravjain131 avatar gauravjain131 commented on May 19, 2024

Hi, does the click_action work from the console when app is in background? Or the APIs need to be used for that also? It works perfectly in foreground case, but not able to get it work in background. Is it a bug or behavior?

from quickstart-android.

seyfullahbilgin avatar seyfullahbilgin commented on May 19, 2024

I have same problem. I tried to use different android service that only get fcm message body string to create custom notification but the same behavior appeared. My notification icon turned to white icon at the background.

Please fix the issue asap. :)

from quickstart-android.

martinodecarlo avatar martinodecarlo commented on May 19, 2024

I had the same issue (the blank icon).

So I tried to use a POST request to https://fcm.googleapis.com/fcm/send through cURL in this way:

curl -i -H "Authorization: key=MY_SERVER_KEY" -H "Content-Type: application/json" -d @nt.json https://fcm.googleapis.com/fcm/send

Now I want to send the notification to all the devices, without specifying the token of each user. However if I don't specify the "to" element in the JSON file, I get error 400.

How can I send my data to all users without specifying their token?

from quickstart-android.

nvhaiwork avatar nvhaiwork commented on May 19, 2024

Can any1 guild me how to send multiple push notification via push API???

from quickstart-android.

diegogui1 avatar diegogui1 commented on May 19, 2024

Hello ,

some time ago published in

http://stackoverflow.com/questions/38020348/send-a-notification-background-firebase-android

a problem that I have with the push notification in foreground and backgrand FCM after you read the link sugueris me to look at my app android?

backgrand foreground and take different style.

Regards,

from quickstart-android.

brianhsux avatar brianhsux commented on May 19, 2024

I have the same question. Is there any simple way to send the data only messages?

from quickstart-android.

Svoka avatar Svoka commented on May 19, 2024

@shinayser I think you just misunderstood how android notifications is working.
This is the CORRECT behavior

from quickstart-android.

Svoka avatar Svoka commented on May 19, 2024

@shinayser Why don't just use CURL or something instead? They'll be done with the console and data notifications soon.

from quickstart-android.

 avatar commented on May 19, 2024

@Svoka you used "notification" as the key, wouldn't it be "data..??
I got this from docs..

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{ "data": {
"score": "5x1",
"time": "15:10"
},
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}

from quickstart-android.

2ndGAB avatar 2ndGAB commented on May 19, 2024

I wonder if we don't face a very recent problem on Android about the ability to receive data-messages while the application is in background.
It worked, for sure as I have a published application built 07/08/16 which perfectly receives data-message sent via API even if it's in background.

But I currently realize that the same project I rebuild now after some updates asked by Google within Studio, cause my application to not receive any data-message anymore while in background.

And that's very new. Could anyone confirm it or not?

from quickstart-android.

hossein-85 avatar hossein-85 commented on May 19, 2024

I am still looking for a way to Customize the notification message , specifically changing the style to BigTextStyle when the app is in the background. I have a relatively large message which gets ellipsized and more often than not the app is in the background when the user receives a notification from our server.

from quickstart-android.

Gloix avatar Gloix commented on May 19, 2024

@2ndGAB Using Firebase 9.2.1 and Play services 9.2.1 notifications arrive in background.

@hossein-85 use the notification fields inside the data field for notifying Android users and then you can make your custom notifications (if you use the notification field you won't get the background notification in your declared Messaging service on Android). Unfortunately this does not work for iOS users, so you have to send separate requests to the Firebase messaging service.

from quickstart-android.

howyongjun avatar howyongjun commented on May 19, 2024

Kind of pain in the ass right now as the behaviour in Android & iOS are different. Android developer unable to make customization in Notification message. It's difficult to show something like (5 new messages from somebody) unless the app server do the calculation which is NOT a good way. Is there any better way other than sending (Data only message to Android & Notification message to iOS)?

from quickstart-android.

kroikie avatar kroikie commented on May 19, 2024

@howyongjun if you want full control of the notification on Android then you should send a data-message and since data messages cannot be received while an iOS app is in the background, you need a notification-message for that, so you would have to send two different notifications to each platform.

I understand the desire to send the same message to both iOS and Android as you would not have to keep track of the platforms, thanks for the feedback on this.

from quickstart-android.

howyongjun avatar howyongjun commented on May 19, 2024

@kroikie I got some question about the collapsible. The problem I'm having is I sent 4 different notification message with 4 different collapse_key while the device is offline, then i reconnect to Internet & ONLY receive the last notification message. Is this an issue or i misunderstood the meaning of collapsible?

from quickstart-android.

tiagoshibata avatar tiagoshibata commented on May 19, 2024

Using Firebase 9.2.1 and Play services 9.2.1 notifications arrive in background.

@Gloix Do you mean data-only messages or are notifications created from Console working for you? Tested latest Firebase on Android and my app doesn't seem to receive notifications created in Console while in background.

from quickstart-android.

kroikie avatar kroikie commented on May 19, 2024

@howyongjun what platform are you checking? collapse_key will not work if you are sending messages to iOS FCM does not hold on to messages sent to iOS devices.

from quickstart-android.

howyongjun avatar howyongjun commented on May 19, 2024

@kroikie i'm using collapse_key for Android only. It seems that some of the behaviour are not the same as what mentioned in the document. For instance, disconnect device from Internet connection --> send different messages with different collapse_key --> reconnect device with Internet connection --> receive only the last message sent. Any idea on this behaviour?

from quickstart-android.

2ndGAB avatar 2ndGAB commented on May 19, 2024

@Gloix did you very recently build a project to verify it still work because It worked for me until begining of july but it don't work anymore for me after recent development environment updates.

from quickstart-android.

Gloix avatar Gloix commented on May 19, 2024

@2ndGAB @tiagoshibata I'm sorry for the delayed response. I just tested with Firebase library 9.2.1 through the Firebase console and I received the notification in background.

from quickstart-android.

2ndGAB avatar 2ndGAB commented on May 19, 2024

@Gloix That's a good news.
Can you tell me which Android Studio version do you use?

Edit
But when you say that you receive notification in background, you mean the notification is received in System tray because AFAIK, Firebase console only send Notification message, maybe with data payload, I don't remember well and so, when the app is in background, notification is received by the system tray and data payload is passed to the application by an Intent when you tap the notification right?

from quickstart-android.

Gloix avatar Gloix commented on May 19, 2024

@2ndGAB Android Studio 2.1.2. Maybe I should also mention that I included a title, a message and that the target was a single user. The target user was running Android Marshmallow.

from quickstart-android.

2ndGAB avatar 2ndGAB commented on May 19, 2024

@Gloix ok so no data payload message

from quickstart-android.

Gloix avatar Gloix commented on May 19, 2024

@2ndGAB Exactly. No data message. I actually didn't include any additional fields in the Firebase console form. Only title, message (I included a message tag as well (the second field in the form) ) and the single target user. App was in background (closed, not open in background), but phone screen turned on.

from quickstart-android.

abdymm avatar abdymm commented on May 19, 2024

halo i have same problem , my icon not show on background notifcation just show white background in bar and not popup like foreground notification
i tested on lollipop device
here is my http request

{
"collapse_key" : "demo",
"priority" : "high",
"data": {
"id" : 123,
"message": "kirim data pakan Kolam Siapapuns",
"title": "Log Pakan",
"type": "feed_log",
"content":
{
"pond_id": 5,
"pond_name": "Kolam Siapapun"
},
},
"notification" : {
"title" : "Title"
"body" : "Haloooooo",
"icon" : "myicon",
"sound" : "default",
"click_action" : "FISH_LOGS"
},
"to" : "el4ol2TYUyg:APA91bG6YrtvgAdNHxLxxxXX"
}

whats wrong with my request ?

from quickstart-android.

2ndGAB avatar 2ndGAB commented on May 19, 2024

@abdymalikmulky Are you supposed to receive your data message in onMessageReceive()?

from quickstart-android.

abdymm avatar abdymm commented on May 19, 2024

first, is the notification showing icon app, sound and other same as property that you set in onMessageReceived() ?
second , how if the app was killed ? the notification still show "normally" ?

from quickstart-android.

abdymm avatar abdymm commented on May 19, 2024

thank you @KishorAndroid , i will try it

from quickstart-android.

nikunjparadva avatar nikunjparadva commented on May 19, 2024

@abdymalikmulky I have same issue ...When you can solved then please Tell Us!!

and How to set BigPictureStyle() in FCM notification when app is in background or Destroyed!!

from quickstart-android.

yayaa avatar yayaa commented on May 19, 2024

Why is this issue closed? Since the main issue was about "Custom Notifications when app is in background or killed" and not solved yet? Does this mean we should not wait for a fix to this? I was really hoping Firebase team to be working on this.

from quickstart-android.

Svoka avatar Svoka commented on May 19, 2024

@yayaa I think you need to read all the thread first. It's definitely not a bug and everything is working as planned

from quickstart-android.

yayaa avatar yayaa commented on May 19, 2024

I know it is as planned, but i thought at least this would be considered as feature demand. Most of the applications icon's somehow has a background, and when firebase applies white tint on it to display as notification icon, it is mostly white squared empty icon or some non-sense icon there. At least, customisation on icon - color and so on. I see on notification message documentation there are some fields like that and i thought maybe it's already done and i missed that, but when i try to send that from console as additional params in advance section, i saw no changes. That's why i actually said no improvements on this topic. @Svoka but thanks anyway.

from quickstart-android.

Svoka avatar Svoka commented on May 19, 2024

@yayaa oh, I think I get it now. In my case I don't need console at all, because we have server with this logic. So we send data-only messages. (Console still can't do this, I guess)
By the way, you can provide icon from console:
it's R.drawable.#_ICON_STRING#

from quickstart-android.

yayaa avatar yayaa commented on May 19, 2024

I know with data messages you can do anything. But we talked about having notification messages sent from console would also be customizable. And then i saw that issue was closed... :(

from quickstart-android.

Svoka avatar Svoka commented on May 19, 2024

@yayaa I guess we need to create separate issue for that :)
In context of possibility to show icon this issue is closed.

Create new issue #139

from quickstart-android.

2ndGAB avatar 2ndGAB commented on May 19, 2024

@Svoka Can you confrm that you build your application with Android Studio 2 to receive data only messages to background application?

from quickstart-android.

2ndGAB avatar 2ndGAB commented on May 19, 2024

@yayaa I don't think if I undertsand you well but if your are talking about icon appearing on status bar when you receive a notification, they are mandatory white on transparent background since Lollipop.
This icon is set like that:

Notification.Builder..setSmallIcon(android.R.drawable.my little_icon)

from quickstart-android.

yayaa avatar yayaa commented on May 19, 2024

Yes, i am aware of that @2ndGAB . But the problem here is when you have an icon with some graph on a solid background, and when firebase automatically creates your notification icon by tinting your application icon as white, it ends up like @abdymalikmulky screenshot.

Anyway since this issue is closed, i will just stop watching until i need to use Firebase again, and just hope them to fix it by then.

from quickstart-android.

2ndGAB avatar 2ndGAB commented on May 19, 2024

@yayaa That's very strange, here is how I create my notification from a data only message, received in onMessageReceived()

        Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.launcher_icon);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_logo_notif)
                .setLargeIcon(bm)
                .setContentTitle(title)
                .setSound(ringURI)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg).setSummaryText(this.getString(R.string.label_service)))
                .setContentText(msg)
                .setContentIntent(contentIntent)
                .addAction(R.drawable.ic_action_place, null, geoPendingIntent)
                .addAction(R.drawable.ic_action_web_site, null, webPendingIntent)
                ;

And here is the result: first the litle monochrome icon white on transparent background
And here is when you open the notification center

You can see that if you provide a valid little icon with setSmallIcon(), you won't have a white square in the status bar, same if you provide a valid large icon with setLargeIcon().

I usually build my icons with Android Asset Studio

from quickstart-android.

jaydip5500 avatar jaydip5500 commented on May 19, 2024

I want to send a image in push message using firebase consol how can i send image in push message any solution.and also i want to custom look of notification..?

from quickstart-android.

jaydip5500 avatar jaydip5500 commented on May 19, 2024

I want to send a image in push message using firebase consol how can i send image in push message any solution.and also i want to custom look of notification..?

from quickstart-android.

tariqul000 avatar tariqul000 commented on May 19, 2024

I send User segment push notification but All user don't get push notification Why all did not get? From console.firebase.google.com I found monthly active user 4100 but when i send notification It shows 2100 send. and every time i got notification in 7 to 10 phones out of 12 different phones. That mean 50% user found notification. then what would be be others.

from quickstart-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.