Notification doesn't show light with sound set - android

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

Related

Notification small icon on status bar creating for every notificaton

I'm creating a notification by
mNotifyBuilder.setContentTitle(envelope.getSubjectWithDefault(context.getString(R.string.no_subject)))
.setTicker(sybject)
.setSmallIcon(icon)
.setContentInfo(name)
.setDeleteIntent(PendingIntent.getBroadcast(context, (int) id, deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT))
.setContentIntent(PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT))
.setAutoCancel(true)
.setNumber(count)
.setGroup(group)
.addAction(reply)
.addAction(cancel, context.getString(R.string.delete), dismiss)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(text))
.setContentText(text);
String noti = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(noti);
mNotificationManager.notify((int) id, notify);
but some phones create for every push their own small icon on the status bar.
How can I found or what I can change in code to fix such notification to work?

Push Notification with action button is not working

i have used the fcm for notification and its coming correctly, but when i try to add add buttons in notification its not showing.
my code
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 notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("New Message From Film")
.setContentText(messageBody)
.setAutoCancel(true)
.addAction(R.drawable.pp, "Accept",pendingIntent)
.addAction(R.drawable.pp, "Reject",pendingIntent)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
You forgot to build use method build() in last
edited code
Builder
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("New Message From Film")
.setContentText(messageBody)
.setAutoCancel(true)
.addAction(R.drawable.pp, "Accept",pendingIntent)
.addAction(R.drawable.pp, "Reject",pendingIntent)
.setContentIntent(pendingIntent);
notification
final Notification notification = notificationBuilder.build();
mNotificationManager.notify(notificationId, notification);

Preview Notification on android

I'm using this code to show a notification to user from code :
Intent intent = new Intent(this, this.getClass());
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.icon)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.icon))
.setContentTitle("Notification!")
.setContentText("Hello word")
.setContentIntent(pi)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setPriority(NotificationCompat.PRIORITY_MAX);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
This is juste adding the notification in the notification screen (and also the icon of my appliaction in the status bar)
But how can I have a preview of this notification on top of screen ?

Show Small Icon in notification Bar but hide in notification Panel

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();

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

Categories

Resources