Android Notification Big Picture Style and Big Text Style - android

I've build a push notification using Big Picture Style as show here.
Is it possible to mix Big picture Style and Big Text Style as shown in the attached photo? How do I do it?

You should be able to do it this way:
Notification notif = new Notification.Builder(context)
.setContentTitle("Title")
.setContentText("content")
.setSmallIcon(R.drawable.ic_small)
.setLargeIcon(bitmap)
.setStyle(new Notification.BigPictureStyle()
.bigPicture(bigBitmap)
.setBigContentTitle("big title"))
.build();
Source

View More... text in your norification is subtext.
So while using bigpicturestyle notification you need to set
bigPicStyle.setSummaryText(mContent);
or
mBuilder.setSubText(mSubText);
Setting both at same time doesn't work.

Example of how to create a BigPictureStyle Notification:
int NOTIFICATION_ID = 1;
String ns = Context.NOTIFICATION_SERVICE;
//Get the bitmap to show in notification bar
Bitmap bitmap_image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
Bitmap big_bitmap_image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle()
.bigPicture(big_bitmap_image)
.setSummaryText(getResources().getString(R.string.content));
NotificationCompat.Builder nb = new NotificationCompat.Builder(this);
nb.setContentTitle("Notification title"))
.setContentText("Notification Content")
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(bitmap_image)
.setTicker("Notification ticker!")
//API Level min 16 is required
.setStyle(style)
.build();
Intent notificationIntent = new Intent(this, MainActivity2.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
TaskStackBuilder TSB = TaskStackBuilder.create(this);
TSB.addParentStack(MainActivity.class);
TSB.addNextIntent(notificationIntent);
PendingIntent resultPendingIntent = TSB.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
nb.setContentIntent(resultPendingIntent);
nb.setAutoCancel(true);
NotificationManager mNotificationManager =
(NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, nb.build());
this is the complete code:
https://github.com/Jorgesys/Android-Notifications

Related

Custom notification view RemoteView does not show up

I have created a notification using a simple layout with textview and imageview. But after calling notificationManager.notify(...); does not show the notification.
Following is the code i have created
// Create notificationmanager instance
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
int importance = NotificationManager.IMPORTANCE_LOW;
// Setting the channelid if versioncode is greater than Oreo's
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel mChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, importance);
notificationManager.createNotificationChannel(mChannel);
}
// Creating remote views for the notifications
RemoteViews notificationLayoutCollapsed = new RemoteViews(context.getPackageName(), R.layout.notification_layout_collapsed);
RemoteViews notificationLayoutExpanded = new RemoteViews(context.getPackageName(), R.layout.notification_layout_expanded);
// Passing the intent
Intent notificationIntent = new Intent(context, HomeActivity.class);-
// setting the flags
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
// Style MOST LIKELY ISSUE IS HERE
NotificationCompat.Style style = new androidx.media.app.NotificationCompat.DecoratedMediaCustomViewStyle();
NotificationCompat.Builder mBuilder1 = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification_icon)
.setContentTitle(context.getString(R.string.app_name))
.setContentText(context.getString(R.string.app_name))
.setContent(notificationLayoutExpanded)
.setCustomContentView(notificationLayoutCollapsed)
.setCustomBigContentView(notificationLayoutExpanded)
.setStyle(style)
.setAutoCancel(false)
.setContentIntent(pendingIntent);
notificationManager.notify(NOTIFICATION_ID, mBuilder1.build());
I have also tried using the style = new NotificationCompat.DecoratedCustomViewStyle();
But when i set the style as BigText or BigPicture and do not set the customcontentview i do see the notification.
Edit
I have used both v4.NotificationCompat, androidx.NotificationCompat
Problem is in my code, I think some step is missing. Pls help.

Display FCM large notification icon

I am new to android. I have created FCM large notification. Now what I want to do, how can I make notification like image Large Imag I trying to make it large icon but I filed. Thank you for help.
FcmMessagingService : java
private void ManualNotification(String title, String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
Bundle bundle = new Bundle();
bundle.putString("message", messageBody);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Bitmap bmp = BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher);
Notification.BigPictureStyle bigpicture = new Notification.BigPictureStyle();
bigpicture.bigPicture(bmp);
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notifcation)
.setContentTitle(title)
//.setContentText(messageBody)
.setLargeIcon(bmp)
.setContentIntent(pendingIntent)
.setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
.setContentText(messageBody).setLights(Color.YELLOW, 300, 300)
.setVibrate(new long[]{100, 250})
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
you can use this link for notification icon size:
notification icon size in android
or if you want to create your custom notification view then you can use RemoteView for that. See sample:
android custom notification tutorial
Try with Notification class:
final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(Context context, String channelId);
Notification notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0)
.setAutoCancel(true)
.setContentTitle(title)
.setContentIntent(resultPendingIntent)
.setSound(alarmSound)
.setStyle(bigPictureStyle)
.setWhen(getTimeMilliSec(timeStamp))
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
.setContentText(message)
.build();

Android push notification showing text in single line

I have search and found solution but that solution is not showing multi line push notification.
My code is below,
int id = (int) System.currentTimeMillis();
Intent intent = new Intent(this, Activity.class);
Bundle bundle = new Bundle();
bundle.putString("id", u_id);
intent.putExtras(bundle);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
intent,
PendingIntent.FLAG_CANCEL_CURRENT
);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this);
Notification notification = mBuilder.setSmallIcon(getNotificationIcon()).setTicker(getResources().getString(R.string.app_name)).setWhen(0)
.setAutoCancel(true)
.setContentTitle(getResources().getString(R.string.app_name))
.setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
.setContentIntent(resultPendingIntent)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setLargeIcon(BitmapFactory.decodeResource(getResources(), getNotificationIcon()))
.setContentText(messageBody).build();
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(id, notification);
How can I show multi line text in push notification?
Intent intent = new Intent(this, target.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Bitmap image= BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.youricon)
.setContentTitle("Title")
.setLargeIcon(image)
.setContentText("Message")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmap).setSummaryText("multiline text"));
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(m/* ID of notification */, notificationBuilder.build());

Android - Big Picture Style image not showing properly

Image in big picture style not showing in proper way. From top and bottom it cuts.
Here is code to generate notification:
private void notificationWithImage(String url, String msg, int smallLogo) {
try {
Bitmap icon1 = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_launcher);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setAutoCancel(true)
.setContentTitle("XXXXXXXAPP")
.setSmallIcon(smallLogo)
.setLargeIcon(icon1);
NotificationCompat.BigPictureStyle bigPicStyle = new NotificationCompat.BigPictureStyle();
// bigPicStyle.bigPicture(Picasso.with(getApplicationContext()).load(url).resize(320, 256).centerInside().get());
Bitmap bitmap_image = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_edited_noti);
bigPicStyle.bigPicture(bitmap_image);
bigPicStyle.setBigContentTitle("XXXXXXXAPP");
bigPicStyle.setSummaryText(msg);
mBuilder.setStyle(bigPicStyle);
if (getLoginDetailFromPrefs())
resultIntent = new Intent(this, Perspective.class);
else
resultIntent = new Intent(this, LoginActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
if (getLoginDetailFromPrefs())
stackBuilder.addParentStack(Perspective.class);
else
stackBuilder.addParentStack(LoginActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
} catch (Exception e) {
e.printStackTrace();
}
}
I added screen shot with question
The thing that you want can be done perfectly by the use RemoteView in Notification & then Apply customView in Builder.
This is a template code to use RemoteViews : -
RemoteViews remoteViews = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_layout);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.notification_small)
.setColor(getApplicationContext().getResources().
getColor(R.color.colorPrimary))
.setCustomBigContentView(remoteViews)
.setLargeIcon(bitmap)
.setContent(remoteViews)
.setOngoing(true)
.setContentTitle("")
.setAutoCancel(false)
.setTicker(getString(R.string.app_name), remoteViews)
.setPriority(Notification.PRIORITY_HIGH)
.setContentText("");
NotificationManager mNotificationManager =(NotificationManager)
getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());

How to apply a big view style to a notification using Parse library

This library works perfectly, but i have a doubt.
When I send a message to users with more than two lines, users can't see all message in notification area.
But I know that ANDROID can do it
http://developer.android.com/guide/topics/ui/notifiers/notifications.html#ApplyStyle. How to do it for notification from parse.com ?
Look the images to explain my problem
Image1 http://gorio.eng.br/parse1.png
Image2 http://gorio.eng.br/parse2.png
Here's an example using Notification.BigTextStyle.
final String someLongText = "fkdljfdldkfj;ldaksjfkladj;flja;lkjdfljadslfjaddfdsfafjdfad" +
"fdl;akjf;lkdf;lkaj;flkjda;lkfjadljflk;adsjfladjflk;dfjlkdjflakdfjdaffjdlfjdjjj" +
"adjflkjadlkfjad;lkfjad;sljf;ladkjajlkfjad;lksfjl;akdjf;lkdsajf;lkdjfkadj;flkad" +
"jf;lkadjfkldas;lkfja;dljf;lkdasjf;lkadjs;lfjas;ldkfj;lkadsjfl;kadljfl;kasdjf;l" +
"jdlskfjklda;fjadslkfj;sdalkfj;ladjf;lajdl;fkajld;kfjlajfl;adjfl;kajdl;fjadl;kfj;";
final Notification.Builder builder = new Notification.Builder(this);
builder.setStyle(new Notification.BigTextStyle(builder)
.bigText(someLongText)
.setBigContentTitle("Big title")
.setSummaryText("Big summary"))
.setContentTitle("Title")
.setContentText("Summary")
.setSmallIcon(android.R.drawable.sym_def_app_icon);
final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(0, builder.build());
Bitmap icon1 = BitmapFactory.decodeResource(getResources(),
R.drawable.gorio);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
getApplicationContext()).setAutoCancel(true)
.setContentTitle("Exemplo 1")
.setSmallIcon(R.drawable.gorio)
.setLargeIcon(icon1).setContentText("Hello World!");
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
bigText.bigText(msg);
bigText.setBigContentTitle("GORIO Engenharia");
bigText.setSummaryText("Por: GORIO Engenharia");
mBuilder.setStyle(bigText);
mBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(getApplicationContext(),
MainActivity.class);
// The stack builder object will contain an artificial back
// stack for
// the
// started Activity.
// getApplicationContext() ensures that navigating backward from
// the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder
.create(getApplicationContext());
// Adds the back stack for the Intent (but not the Intent
// itself)
stackBuilder.addParentStack(MainActivity.class);
// Adds the Intent that starts the Activity to the top of the
// stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(100, mBuilder.build());
This snippet shows how to construct the Builder object. It sets the style for the big view to be big text, and sets its content to be the reminder message.
String msg="This is Big style notification builder.This is Big style notification builder.This is Big style notification builder.This is Big style notification builder.This is Big style notification builder.This is Big style notification builder.This is Big style notification builder.This is Big style notification builder.This is Big style notification builder.This is Big style notification builder."
// Constructs the Builder object.
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_notification)
.setContentTitle(getString(R.string.notification))
.setContentText(getString(R.string.ping))
.setDefaults(Notification.DEFAULT_ALL) // requires VIBRATE permission
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(0, builder.build());
For more infomation go to:http://developer.android.com/training/notify-user/expanded.html
Here I have attached a screenshots, the first screen contents a title of the post and when we click on the down arrow on right side of the app name it leads to the second screenshot which is custom layout for push notification.The following is sample layout that I have designed for mine.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
card_view:cardCornerRadius="5dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:background="#80000000"
android:layout_height="wrap_content">
<ImageView
android:src="#mipmap/ic_launcher"
android:layout_width="50dp"
android:layout_height="match_parent"
android:padding="10dp"
android:layout_marginLeft="5dp"
android:background="#null"
android:layout_gravity="center_vertical|center_horizontal"
android:scaleType="centerCrop"/>
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:minHeight="48dp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:background="#android:color/transparent"
android:textColor="#android:color/white"
tools:text="Test"/>
</LinearLayout>
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:contentDescription="#null"
android:scaleType="centerCrop"
android:src="#drawable/placeholder"/>
</LinearLayout>
Method for creating Notification with custom layout,
public static void createNotification(String title, String body,String image_url, Context context, int notificationsId, String single_id) {
Intent notificationIntent;
long when = System.currentTimeMillis();
int id = (int) System.currentTimeMillis();
Bitmap bitmap = getBitmapFromURL(image_url);
NotificationCompat.BigPictureStyle notifystyle = new NotificationCompat.BigPictureStyle();
notifystyle.bigPicture(bitmap);
RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.custom_notification_layout);
contentView.setImageViewBitmap(R.id.image, bitmap);
contentView.setTextViewText(R.id.title, body);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setStyle(notifystyle)
.setCustomBigContentView(contentView)
.setContentText(body);
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationIntent = new Intent(context, SinglePost.class);
notificationIntent.putExtra("single_id",single_id);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(context, id, notificationIntent, 0);
Notification notification = mBuilder.build();
notification.contentIntent = contentIntent;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
mNotificationManager.notify(notificationsId, notification);
}
public static Bitmap getBitmapFromURL(String strURL) {
try {
URL url = new URL(strURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
you set
String en_alert ,th_alert ,en_title,th_title ,id;
int noti_all, noti_1, noti_2, noti_3, noti_4 = 0, Langage;
Intent intent = new Intent(context, ReserveStatusActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
NotificationManager notificationManager =
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
intent = new Intent(String.valueOf(PushActivity.class));
intent.putExtra("message", MESSAGE);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(PushActivity.class);
stackBuilder.addNextIntent(intent);
// PendingIntent pendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
// android.support.v4.app.NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
// bigStyle.bigText((CharSequence) context);
notification = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(th_title ) // th_title >>> String = th_title
.setContentText(th_alert) // th_alert>>> String = th_title
.setAutoCancel(true)
//.setStyle(new Notification.BigTextStyle().bigText(th_alert)
.setStyle(new NotificationCompat.BigTextStyle().bigText(th_title))
.setStyle(new NotificationCompat.BigTextStyle().bigText(th_alert))
.setContentIntent(pendingIntent)
.setNumber(++numMessages)
.build();
notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notificationManager.notify(1000, notification);
Facebook facebook.com/PongLoveWii
final String someLongText = "......";
final Notification.Builder builder = new Notification.Builder(this);
builder.setStyle(new Notification.BigTextStyle(builder)
.bigText(someLongText)
.setBigContentTitle("Big title")
.setSummaryText("Big summary"))
.setContentTitle("Title")
.setContentText("Summary");
final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(0, builder.build());
you can build notification with big Text Style
try this code
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(id /* ID of notification */, notificationBuilder.build());
You need to override the method getNotification of your ParsePushBroadcastReceiver subclass and above there is a lot answers telling how to set the big content view on a Notification.

Categories

Resources