Android notification white circle when app is not running [duplicate] - android

This question already has answers here:
Notification Icon with the new Firebase Cloud Messaging system
(10 answers)
Closed 6 years ago.
I'm using Firebase Notification for my app's push notifications.
All working well but notification icon shows white circle when app is not running.
I'm targeting SDK version 23, also I'm using Roman Nurik's notification icon generator to generate white-on-transparent icons.
Notification icon is showing correctly when app is on foreground and running. img
But icon gets replaced with generic white circle when app is in background or killed. img
Here's my notification builder method:
private void sendNotification(String messageTitle, 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);
NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_notification_icon)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
.setAutoCancel(true)
.setPriority(Notification.PRIORITY_DEFAULT)
.setDefaults(Notification.DEFAULT_ALL)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notification.build());
}

I've already found an answer on similar issue: Notification Icon with the new Firebase Cloud Messaging system
Unfortunately this is a limitation of Firebase Notifications in SDK
9.0.0. When the app is in the background the launcher icon is use from the manifest (with the requisite Android tinting) for messages sent
from the console.
If the app is in the foreground (or a data message is sent) you should
be able to use your own logic to customise, and you should be able to
customise the icon if sending the message from the HTTP/XMPP APIs.
Right now with messages sent from the console you'll get this
behavior.
It seems to be that the best way to avoid this Firebase Notifications bug is to change your targetSdkVersion in build.gradle to 19. The notification icon will be then colored. Firebase after a while will fix this issue.
Hope it will help

try this code:
Intent intent = new Intent(this, TabActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(getNotificationIcon())
.setContentTitle("IDS DMS Support")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

I think that you need to add a silhouette icon to the app and use it if the device is running Android Lollipop.
Use below code to get small icon for notification.
protected int getNotificationIcon() {
boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
return useWhiteIcon ? R.drawable.ic_silhouette : R.drawable.ic_launcher;
}
You can see full solution Here.
I did same thing and works fine.

Related

startForegroundService - unable to use setContentIntent + addAction?

Unfortunately another question about my startForegroundService notification... I searched, really, I did:
I have a foreground service that is running perfectly. I would like to add a couple of actions to this notification. For one, make it so when the user clicks the notification they are sent to MainActivity as well as adding a "Quit" addAction.
Here is the snippet I am using to create the notification:
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,0);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
String channelId = getNotificationChannel(notificationManager);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId);
Notification notification = notificationBuilder.setOngoing(true)
.setCategory(NotificationCompat.CATEGORY_SERVICE)
.setSmallIcon(R.drawable.ic_notif_icon)
.setContentTitle("My app")
.setContentText("Background service is running...")
.setContentIntent(pendingIntent)
.build();
startForeground(13365, notification);
Using the above a notification shows up just fine, but click on it results in nothing. I also tried using addAction, also nothing. I am aware the syntax is a little bit different (....Action.Builder) when adding an addAction.
I am creating my notification in the onCreate handler of the foreground service. Running on SDK 26.
Can startForeground notifications have setContentIntent / addAction attached to them?
Thanks!
Solved : I had the notification replaced elsewhere in my application and was not adding the intents there.
Doh!

Xamarin.Forms (AltBeacon Android Library) - Send local notification when detected beacon in background [duplicate]

This question already has an answer here:
How to range beacons in background using Altbeacon: Android Beacon Library?
(1 answer)
Closed 2 years ago.
I appreciate some feedback on how to handle this:
App in foreground works fine, detects beacons and I can generate local notifications from there. When app is in background or terminated I still can bring it back to life when beacon gets in range, but that "forces" me to open the app. I would like the following behavior:
App should send local notification silently when detects beacons in background and not open app. My local notification should have then Intent to open app when I click them.
From here they have the correct scenario, but then the sample doesn't seem to do what should.
https://altbeacon.github.io/android-beacon-library/notifications.html
Any help is much appreciated.
Thank you,
Bruno
I wrote that sample, which is written in Java for Android. I can confirm it does work as shown, but on apps targeting Android 9+ you must also create a notification channel for all notifications. In Java, you can do that like this:
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setContentTitle("Beacon Reference Application")
.setContentText("An beacon is nearby.")
.setSmallIcon(R.drawable.ic_launcher);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addNextIntent(new Intent(this, MonitoringActivity.class));
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
builder.setContentIntent(resultPendingIntent);
NotificationManager notificationManager =
(NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("My Notification Channel ID",
"My Notification Name", NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription("My Notification Channel Description");
NotificationManager notificationManager = (NotificationManager) getSystemService(
Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);
builder.setChannelId(channel.getId());
}
notificationManager.notify(1, builder.build());

How to handle the case when click_action was sent to the previous version of the app where intent-filter was not added yet?

Could you help me to solve the problem?
The task is develop push notification that will open particular Activity by users tap.
I've added intent-filter and tried to send the push message with the click_action field, and everything works like a charm.
The problem is with the previous version of the application where Intent-filter was not added yet. If user tap on the push message (in the case of previous app version), nothing happens.
What is better to do in this case? How to handle such situations?
Edit:
So the question is, how can we have default behavior (opening the app on the last screen) in the case of specific screen mentioned in click_action field and lacking of necessary intent-filter? This relevant for situation when the user has previous version of the app without necessary intent-filter in the manifest file.
To perform some action on push-notification click we need to write code for that to perform such action. In your case you want to perform some action on your old live application, In this can you can't do anything.
To perform some action you can call this method on push notification received
private void sendNotification(String title, String messageBody) {
Intent intent = new Intent(this, YourActivityName.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
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)
.setContentTitle(title)
.setContentText(messageBody)
.setVibrate(new long[]{01})
.setAutoCancel(true)
.setContentIntent(pendingIntent);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
notificationBuilder.setSmallIcon(R.mipmap.notification);
else
notificationBuilder.setSmallIcon(R.mipmap.notification);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, notificationBuilder.build());
}

How to disable multiple push Notification icon in Android, Am using Parse.com

com push notification for Android app, All is working well but lets say if i send 5 push notification a day, i dont want user to see 5 notification icons at once on his phone. Its best if he sees only one.So is their any way where old notification is deleted and only latest is shown.
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
The method that displays the notification has an int parameter which represents the notification identifier. If you use a constant identifier, each new notification will replace the previous one.
you have to set the notification ID to be the same value. So then they get replaced as each one arrives.
int notificationId = 1 ;
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setAutoCancel(true);
builder.setSmallIcon(R.drawable.gcm_logo);
builder.setContentTitle("Test Title");
builder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, builder.build());
So you can maintain notification Id for different type of notifications. If you keep same notification ID for each notification then it would be updated in the same .
If you have any extras in the pending intent and you want to update those extras with the latest ones then generate pending intent with :
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(),
PendingIntent.FLAG_ONE_SHOT);

Android - Post a notification to status bar?

I am trying to post a notification to the status bar without any intent, but nothing is happening?
Am I missing anything? This code is inside my push notification receiver service.
notificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle("Hello");
builder.setContentTitle("This is my message");
builder.setSmallIcon(R.drawable.ic_launcher);
PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
builder.setFullScreenIntent(intent, true);
notificationManager.notify(555, builder.build());
As mentioned in my comment, to create a notification for the notification manager, a small icon must also be provided.
Additionally, for developers targeting Android 2.2 and 2.3 as well, make sure to include a content Intent otherwise the app will crash.

Categories

Resources