Android Notification not showing in LG and some other devices - android

I have used the following code to display a notification while starting service in the foreground.
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class), 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.statusbar_icon)
.setContentTitle("App is running")
.setStyle(new NotificationCompat.BigTextStyle())
.setPriority(Integer.MAX_VALUE)
.setDefaults(Notification.DEFAULT_ALL);
mBuilder.setContentIntent(contentIntent);
startForeground(R.string.service_running, mBuilder.build());
The notification is showing in the notification bar of all devices except LG-E450 and a Samsung device. Not only this one, no notification from my application is not showing in the bar.

The documentation states that detail text is required and can be set via NotificationCompat.Builder#setContentText(CharSequence) (although my GS3 will display a notification without detail text)

In the App settings 'Show Notifications' has beeen turned off so it should be trun on

Related

How to make notification stay on top?

I have a notification which I always want to stay on top.
I have already given it a priority of 2
Mostly it stays on top but, suppose there is a open WiFi network, then my notification goes down and the notification of open WiFi network comes on the top position.
But when I looked at the notification of vlc(for Android) paying a song, the notification of vlc stay on top and the notification of open WiFi network goes down.
I notification is ongoing and with priority 2.
What should I do. I am a beginner so please bear with me.
And thanks in advance.
have you tried this
NotificationCompat.Builder builder =
(NotificationCompat.Builder) new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.notify_icon)
.setContentTitle("Notification")
.setContentText("ON Top")
.setPriority(Notification.PRIORITY_MAX);
Priority Levels --> PRIORITY_MAX / PRIORITY_HIGH /PRIORITY_DEFAULT /PRIORITY_LOW /PRIORITY_MIN
read
https://material.google.com/patterns/notifications.html#correctly_set_and_manage_notification_priority
https://developer.android.com/reference/android/app/Notification.html#priority
and as StenSoft said
Android: How to create an "Ongoing" notification?
I think you can refer to this code:
Intent push = new Intent();
push.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
push.setClass(this, NotificationDemo.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, push, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationManager nm=(NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
Notification updateNotification = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_face_black_24dp)
.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher))
.setContentTitle("Priority Max Notification Title")
.setContentText("Priority Max Notification Message")
.setAutoCancel(false)
.setDefaults(Notification.DEFAULT_SOUND)
.setPriority(Notification.PRIORITY_MAX)
.setFullScreenIntent(pi,true)
.build();
nm.notify("priorityMaxTest",2,updateNotification);

Notifications are not showing on some devices when App is not in foreground

on some devices (seems to be api level independend, in this case Samsung S5 and Samsung Galaxy Tab 3 8" with Stock ROMs) the notifications are only shown when app is in foreground but not when it is in background.
I am sure that the service is running because I can see that in the android settings and it also works on other devices without problems.
public void generateProgressNotification(String title, String message) {
long[] vibrate = new long[]{300};
Intent intent = new Intent(mApplicationContext, MainActivity.class);
intent.putExtra(NotificationHelper.START_SHOW_PROGRESS, true);
PendingIntent contentIntent = PendingIntent.getActivity(mApplicationContext, 0, intent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mApplicationContext)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(title)
.setVibrate(vibrate)
.setContentIntent(contentIntent)
.setLights(mApplicationContext.getResources().getColor(R.color.primary), 200, 200)
.setContentText(message);
NotificationManager mNotificationManager = (NotificationManager) mApplicationContext.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(PROGRESS_NOTIFICATION_ID, mBuilder.build());
}
Has anyone an idea why the notifications does not work on all devices?
Best regards,
Moritz
In newer versions of android devices. The notification is only pushed if the user using the application. If application is not running then notification will be pushed on next run. I also had the same problem and then I searched for the issue and even used wakeful broadcast receiver but the problem was not solved.

What is the difference between Notification and NotificationManger in Android?

What is the difference between those two?
I want to use the startForeground method and cannot use it with NotificationManager..
Thanks
A Notification is a class that represents either a persistent icon that goes in the status bar and is accessible through the launcher, turning on or flashing LEDs on the device, or alerting the user by flashing the backlight, playing a sound, or vibrating.
The Notification Manager is the class that allows you to add notifications to the system,
startForeground is a method of the Serivce class. For example inside your Service class you can have something like this.
Intent notificationIntent = new Intent(this, ActivityMain.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_stat_play)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
.setTicker(getString(R.string.app_name))
.setWhen(System.currentTimeMillis())
.setOngoing(true)
.setContentTitle(getString(R.string.app_name))
.setContentText(someText);
Notification notification = builder.build();
startForeground(1, notification);
A Notification is a description of what you want to occur to alert the user about something -- what icon goes in the status bar, what ringtone to play, etc.
NotificationManager is a system service that can show a Notification.
I want to use the startForeground methode and cannot use it with NotificationManager
Correct. Create a Notification using Notification.Builder (or NotificationCompat.Builder). See this project for an example of using startForeground().

Android how to compose notification on notification bar

I am new to android. I want to now how to create a notification in the notification bar and compose it like 'usb connected' or 'usb debugging connected' notify. Can anyone help me with some codes?
I have used NotificationCompat.Builder for the purpose
First we have to style the notification
NotificationCompat.Builder mBuilder=new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher) // icon to be displayed
.setContentTitle("Notification") // title for the notification
.setContentText(msg); // msg is some text you want to display
For Led light blinkering when notification is received
mBuilder.setLights(Color.BLUE,1000,1200);
To give notification sound you can make use of default notification sound set by the user
Uri sound=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
mBuilder.setSound(sound);
To cancel the notification when the user has selected it
mBuilder.setAutoCancel(true);
To start an activity in app when the user clicks the notification
Intent resultIntent = new Intent(this,ExampleActivity.class);
PendingIntent resultPendingIntent =PendingIntent.getActivity(this,0, resultIntent,0);
mBuilder.setContentIntent(resultPendingIntent);
Finally to show the notification in the bar make use of notification manager
NotificationManager mNotificationManager =
(NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

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