Show Small Icon in notification Bar but hide in notification Panel - android

I try to find this one in this forum and I found a couple but no one worked for me. I just need to hide it in the notification panel where appears next to the large icon but if I hide it, it also dissapears from the notification bar.
Is there any way to show only the large icon as is happening in the first and fourth notifications?
This is the code that I am using:
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent;
Notification.Builder mBuilder =
new Notification.Builder(this)
.setSmallIcon(R.mipmap.small_icon).setTicker(getApplicationContext().getResources().getString(R.string.app_name))
.setLargeIcon(largeIcon)
.setAutoCancel(true)
.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000})
.setLights(Color.GREEN, 1000, 1000)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentTitle(extras.getString("title"))
.setStyle(new Notification.BigTextStyle().bigText(extras.getString("message")))
.setContentText(extras.getString("message"));
edit.putString(Config.FRAGMENT, extras.getString("fragment"));
edit.commit();
intent = new Intent(this, NavigationActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
intent, 0);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

You can make it invisible after building the notification :
int smallIconId = context.getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());
if (smallIconId != 0) {
notification.contentView.setViewVisibility(smallIconId, View.INVISIBLE);
notification.bigContentView.setViewVisibility(smallIconId, View.INVISIBLE);
}

working for me.
try it
Notification.Builder builder=new Notification.Builder(this);
builder.setContentIntent(intent)
.setSmallIcon(R.drawable.ic_notification).setTicker(context.getResources().getString(R.string.app_name))
.setContentTitle(context.getResources().getString(R.string.app_name))
.setContentText(message);
Notification notification = builder.build();

Related

Deleting notification from Android notification bar

I'm using the following to code to send a notification:
NotificationCompat.Builder builder =
new NotificationCompat.Builder(getBaseContext())
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("Title")
.setContentText("Message");
int NOTIFICATION_ID = 12345;
Intent targetIntent = new Intent(getBaseContext(), MainActivity4.class);
PendingIntent contentIntent = PendingIntent.getActivity(getBaseContext(), 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);
NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nManager.notify(NOTIFICATION_ID, builder.build());
The code works as I expected except for one little thing, once I go to the notification bar, expand it and choose the notification, it keeps staying on the notification bar, opposite to the behavior of most notifications, than once you tap them they disappear from being there.
Guess it must be some option in the configuration of the notification but as much as I search I cannot find it.
Hope you can help.
Are you looking for this?
.setAutoCancel(true)
so you would have
NotificationCompat.Builder builder =
new NotificationCompat.Builder(getBaseContext())
.setSmallIcon(R.drawable.notification_icon)
.setAutoCancel(true)
.setContentTitle("Title")
.setContentText("Message");

FullScreen Notification

I want to create a full screen notification.I have achieved a notification by using the following code. What changes do i need to make it a full screen notification.
private void showNotification(String data) {
Intent i = new Intent(this, MapsActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle("FCM Test")
.setContentText(data)
.setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
.setContentIntent(pendingIntent);
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(0,builder.build());
}
You can convert simple notification to full screen notification just added a simple line of code builder.setFullScreenIntent(pendingIntent, true); following is full example. I hope this code help you
Full Screen Notification Code:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(android.R.drawable.btn_star);
builder.setContentTitle("This is title of notification");
builder.setContentText("This is a notification Text");
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
Intent intent = new Intent(Broadcastdemo.this, ThreadDemo.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 113,intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
builder.setAutoCancel(true);
builder.setFullScreenIntent(pendingIntent, true);
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(115, builder.build());
On your builder, just before setContentIntent(pendingIntent);
Simply add the following line: .setFullScreenIntent(pendingIntent, true);
try to add both setStyle and setPriority as the following: (it is working fine for me)
.setStyle(new Notification.BigTextStyle().BigText(message.Long_Message))
.setPriority((int)NotificationPriority.Max)

Notification doesn't show light with sound set

When I add .setDefaults(DEFAULT_SOUND) or DEFAULT_LIGHTS or DEFAULT_ALL, it shows the heads up notification, but doesnt show the light set with .setLights(0x0FF00FF0, 300, 100). If I remove the .setDefaults it doesn't show the heads up, but shows the lights.
Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
notificationIntent.setData(Uri.parse("http://www.wgn.com"));
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification = new NotificationCompat.Builder(this)
.setCategory(Notification.CATEGORY_MESSAGE)
.setContentTitle("Yi Warning")
.setContentText("Battery is below 20%")
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.setVisibility(1)
.setContentIntent(contentIntent)
.setPriority(Notification.PRIORITY_MAX)
.setDefaults(Notification.DEFAULT_SOUND)
.setLights(0x0FF00FF00, 300, 100).build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, notification);
Removed
.setDefaults(Notification.DEFAULT_SOUND)
and added
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
Now everything is working great :D

Update Notification without Collasping notification drawer

i have a notification manager that launches an activity when clicked.
mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setOngoing(true)
.setOnlyAlertOnce(true)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setContent(remoteViews)
.setAutoCancel(false);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, Launch.class).putExtra("type", 0), 0);
mBuilder.setContentIntent(pendingIntent);
the function performed in this can also be be asynchronous depending on the users preference. I want to update the notification to an ongoing progress. something of this nature:
mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setOngoing(true)
.setContentTitle("Sending details")
.setPriority(NotificationCompat.PRIORITY_MAX)
.setProgress(100, 0, true)
.setOnlyAlertOnce(true)
.setAutoCancel(false);
when the notification is selected. This is achieved but what i want to do is update the notification from the former to the later without having to first slide up the navigation drawer.
Try this..
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
you need NOTIFICATION_ID to updated the specific notification.
Please refer this

How to set notification icon on android lollipop version

I am using this code for notification. its work on all version but in lollipop it show the white icon in place of my notification icon.
private void sendNotification(String msg) {
//Notification notifyObj = null;
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MenuActivity.class), Intent.FLAG_ACTIVITY_NEW_TASK);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.appicon)
.setContentTitle("New Notification")// Vibration
.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
.setLights(Color.RED, 3000, 3000)
.setWhen(System.currentTimeMillis())
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg);
mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
You need to check SDK version before setting small icon.
Instead of
.setSmallIcon(R.drawable.appicon)
use
.setSmallIcon(CallNotiIcon())
and inside CallNotiIcon method, use this
private int CallNotiIcon() {
boolean Icon = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
return Icon ? R.drawable.appicon : R.drawable.<NEW ICON FOR LOLIPOP>;
}
Make sure you check http://developer.android.com/design/style/iconography.html

Categories

Resources