Lock screen notification text - android

I am building and easy android app.
I am having trouble with notification. When the app receive the notification it shows it properly as heads up with all the picture and the text, while on the lock screen, if the phone is locked, does not show the text. To see the text I have to swipe the notification down.
This is the code:
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
bigText.bigText(body);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_stat_luceterna_notifica_90)
.setContentTitle("Luceterna")
.setLargeIcon((((BitmapDrawable) this.getResources().getDrawable(R.mipmap.ic_launcher_lux)).getBitmap()))
.setAutoCancel(true)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
mBuilder.setStyle(bigText);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
mBuilder.setSound(alarmSound);
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Can please anyone help me? I cannot find any answer to the problem.
Thanks in advance.

I know it's been a while since you asked this question, but I encountered same problem today, and found a sollution.
To solve this problem, you have to override NotificationCompat setContentTitle and
setContentDescritption
With BigTextStyle ones: setBigContentTitle and bigText
You have to use them both, with same texts inside. So, your code would look like:
String title = "Title";
String description = "Description";
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
bigTextStyle.setBigContentTitle(title);
bigTextStyle.bigText(description);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setContentTitle(title)
.setContentText(description)
.setSmallIcon(R.drawable.ic_launcher)
.setStyle(bigTextStyle);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher) // notification icon
.setContentTitle("Notification!") // title for notification
.setContentText("Hello word") // message for notification
.setAutoCancel(true); // clear notification after click
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
An example to help you

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

Notification removed to left or right

I'm programming an android app, which shows a notification. I know how to show it but how can my app learn whether it is removed by being swiped right or left? Is there any way to know this?
This is the way I created the notification:
public void showNotification(){
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setSmallIcon(R.mipmap.ic_launcher);
mBuilder.setContentTitle("My notification");
mBuilder.setContentText("Hello World!");
Notification mNotification = mBuilder.build();
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(R.id.note, mNotification);
}

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)

Android Push notification is not working on Model number- vs450pp having version 4.4.2

I am getting push notification on Android phone on given model number but when I clicked on the notification, It disappear and doesn't open app. I would be grateful If anyone get me out from that problems.
Try Following Code May be work for you .
Intent intent = new Intent(this, MainActivity.class); //define your application activity name which you want to open.
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Application Title")
.setContentText(message)
.setContentIntent(pIntent)
.setSound(soundUri); //This sets the sound to play
notificationManager.notify(0, mBuilder.build());

Notification Bar in android

I am making an application that uses notification in it but when the notification is about to appear this message is appearing continuously till i turn of the AVD "Unfortunately , System UI has stopped"
Intent viewIntent = new Intent(getBaseContext(), WorkshopActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getBaseContext())
.setSmallIcon(R.drawable.web)
.setContentTitle(getResources().getString(R.string.app_name))
.setContentText("Scheduled")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent).setTicker("Compass");
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
notificationBuilder.setStyle(inboxStyle);
notificationBuilder.setStyle(inboxStyle);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int NOTIFICATION_ID = 100;
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
can you please replace getBaseContext() with 'this' or at least getApplicationContext() because BaseContent has a very rare & spesific usage.
and
.setContentIntent(pendingIntent).setTicker("Compass");
after this can you build the notificationBuilder,
.setContentIntent(pendingIntent).setTicker("Compass").build();
maybe it needs to build before adding style and addign it to manager.
lastly,
notificationManager.notify(NOTIFICATION_ID, notificationBuilder);

Categories

Resources