Removing the secondary icon from android notification - android

How can I remove the secondary smaller icon on the bottom right of a notification? Since it's required that we call the setSmallIcon method for the notification, we can’t just remove the call for this method.
Is there any way to remove the secondary icon while retaining it on the status bar? Do we have to call setStyle and set a custom style for the notification?

I got rid of it like that (works for Android 5 and below):
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Bitmap notificationLargeIconBitmap = BitmapFactory.decodeResource(
context.getResources(),
R.drawable.notification_icon_big);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_notification_systray)
//.setLargeIcon(notificationLargeIconBitmap)
.setContentTitle(context.getString(R.string.app_name))
.setContentText(msg)
.setColor(context.getResources().getColor(R.color.blue))
.extend(new NotificationCompat.WearableExtender().setBackground(notificationLargeIconBitmap));

Related

Multiline Notification title

I need to show the notification title in two lines but am not able to do so. I have tried to use setStyle() for this but doesn't seem to be working.
My Notification builder code ::
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setSmallIcon(R.mipmap.icon_not);
mBuilder.setColor(getResources().getColor(R.color.colorPrimary));
mBuilder.setContentTitle("")
.setStyle(new NotificationCompat.BigTextStyle().setBigContentTitle(notTitle))
.setContentText(notBodyInt)
.setAutoCancel(true)
.setContentIntent(resultPendingIntent);
Still the notification title is getting wrapped up in a single line.

how to remove a persistent notification after setongoing(true)?

Here is the code that I'm using to create a notification in Android. This notification is shown as intended and isn't getting removed by swiping the notification.
But I'm unable to remove it programmatically. How should I remove it?
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(getApplicationContext(), Constants.CHANNEL_ID)
.setSmallIcon(R.drawable.small)
.setContentTitle("persistent")
.setContentText("cant remove").setOngoing(true);
mBuilder.build();
In this answer there's a nice explanation on how to do it:
https://stackoverflow.com/a/19268653/3853450
In your case should be something like this:
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(Constants.CHANNEL_ID);
Also, as given in the original answer:
NotificationManager

how to put expand icon in notification in android

i'm trying to put expand icon in notification on my developing app. I already done notification RemortView collapse and expand Layout helping with this site.Below pitcher is my current status of my notification.
My Code given below:
NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
builder.setContentIntent(intent);
builder.setTicker(mContext.getResources().getString(R.string.custom_notification));
builder.setSmallIcon(R.drawable.ic_notification_small_basket);
builder.setAutoCancel(true);
builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
builder.setCustomBigContentView(expandedView);
builder.setCustomContentView(contentView);
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, builder.build());
Actual my need is how to put expand icon and how to get that clicking event from notification RemortView using for expand and collapse the notification.
Look like below pitcher.
This pitcher is just a example for that expand icon.
please assist me.
I know its an old question, but for the sake of the nature of Stack Overflow, I'll give you a proper answer.
Instead of implementing your own header including an arrow to expand/collapse the notification, you might want to decorate your custom notifiction with Androids default header.
The only thing you should take care about is to use the builder methods in the proper order to accomplish your task.Fist you have to set the remote views for collapsed and expanded RemoteViews (what you call RemortViews), and THEN you wrap the NotificationCompat.DecoratedCustomViewStyle around it.
notificationBuilder.setCustomContentView(contentView)
.setCustomBigContentView(expandedView)
.setStyle(NotificationCompat.DecoratedCustomViewStyle()) // <- That's what you want
val notification = notificationBuilder.build()
Do not forget to delete your custom header stuff as it does not make sense anymore.
Click here for the documentation
OK now that we have code I tried this and it worked for me you will need to do some adjustments on where and what is stored
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher))
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
android.app.NotificationManager notificationManager =
(android.app.NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

BigPictureStyle Notification not showing properly in Xiaomi MIUI-8

I wanted to display a bigPictureStyle Notification in MiUi(don't want to use custom view) using the following code--
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(msg)
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(BitmapFactory.decodeResource(getResources(), R.drawable.b))
.setBigContentTitle(title));
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(10, mBuilder.build());
It works perfectly on raw android but in Xiaomi MIUI 8 (Android Lollipop based) it shows a shadow at the bottom of expanded notification view as in the picture--
How to remove this bottom shadow?
The only solution for now is using a custom view with similar looking big content view.

How to show notification in status bar?

So i have created this notification in my activity
Notification n = new Notification.Builder(getApplicationContext())
.setContentTitle("New mail from " + sender)
.setContentText(subject)
.setSmallIcon(R.drawable.notification)
.build();
How can i now show it in status/notification bar along with the sound?
There is some good documentation at android developer site
and have a look at the NotificationManager doc's
Here you go, some code...:
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(mId, n);
Note that it is also a goo idea to add your intend to the notification...
mBuilder.setContentIntent(resultPendingIntent);
To add sound you can use the Notification.Builder.setSound() method.
How can i now show it in status/notification bar along with the sound?
Use the Notification.Builder.setSound() method.
You can get the default ringtone like this:
Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
and then set it as notification sound:
Notification.Builder(getApplicationContext()).setSound(uri);
and then after you've built your notification you launch it with:
myNotificationManager.notify(myNotificationId, n);

Categories

Resources