Custom design of android push notification - android

How can I specify some custom logo and styling information to text. Or some custom action buttons just like music player notification in Android.
PS : I have successfully configured GCM with my app and is able to receive notification from GCM servers. And app is developed using cordova

You should read more about rich notifications in Android. From official documentation:
To have a notification appear in an expanded view, first create a NotificationCompat.Builder object with the normal view options you want. Next, call Builder.setStyle() with an expanded layout object as its argument.
Please see example below:
NotificationCompat.BigTextStyle textDiv = new NotificationCompat.BigTextStyle();
textDiv.bigText(bodyMessage);
notification = new NotificationCompat.Builder(context)
.setTicker(bodyMessage)
.setContentTitle(titleMessage)
.setSmallIcon(notificationIcon)
.setStyle(textDiv)
.setPriority(1)//priority high
.setVibrate(new long[0])
.build();
More info you could see in official documentation here and here

Related

Local notifications implementation

I'm trying to implement Local notifications(with click events and HeadUP Notifications) for my android application using Xamarin.Forms. I've followed Microsoft documentation for Local Notifications but I don't know how to implement this.Can anyone please share any working sample for this.
Thank You.
From Android official document ,there are two ways to set importance level.
First Solution: (Not Work)
If a notification's priority is flagged as High, Max, or full-screen, it gets a heads-up notification.
Examples of conditions that may trigger heads-up notifications include:
The notification has high priority and uses ringtones or vibrations.Using physical device to have a try as follow:
builder.SetVibrate(new long[0]);
builder.SetPriority((int)NotificationPriority.High);
Here is a similar discussion about Heads-up notification.
Unfortunately, the above solution does not work.
Second Solution:(Work)
The correct way in Xamarin Android can set property of Channel .If channel created by NotificationImportance.High,then can show heads-up.You can refer to this official sample.And Modify your CreateNotificationChannel method as follow:
void CreateNotificationChannel()
{
if (Build.VERSION.SdkInt < BuildVersionCodes.O)
{
// Notification channels are new in API 26 (and not a part of the
// support library). There is no need to create a notification
// channel on older versions of Android.
return;
}
var name = Resources.GetString(Resource.String.channel_name);
var description = GetString(Resource.String.channel_description);
//Replace follow NotificationImportance.Default to NotificationImportance.High
var channel = new NotificationChannel(CHANNEL_ID, name, NotificationImportance.High)
{
Description = description
};
var notificationManager = (NotificationManager) GetSystemService(NotificationService);
notificationManager.CreateNotificationChannel(channel);
}

Mixpanel push notification text not getting enlarged on Android devices

Account details on Mixpanel:
maaz.shaikh#bwellthy.com
Notification text: Hey {{USER_NICK_NAME}}, you can check your HbA1c test result by clicking on it, then click GET STARTED to start your journey with us.
Notification custom packet: { "mp_icnm_l": "app_logo", "mp_icnm_w": "notification_logo", "mp_color": "#FF7531", "sound": "yes", "vibrate": "yes"}
The notification pops up on android device like this, but does not enlarge on dragging it downwards
I am using the latest release of Mixpanel(v5.2.1) in the Android code.
Mixpanel is using BigStyle Text notifications in their library, so ideally the single line notification on dragging should enlarge on dragging it.
Can you tell me the possible reason for this?
Use BigTextStyle for setting big text in notification.
Notification notification = new Notification.Builder(mContext)
.setContentTitle("New mail from " + sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_mail)
.setLargeIcon(aBitmap)
.setStyle(new Notification.BigTextStyle()
.bigText(aVeryLongString))
.build();

Notification with setGroupSummary(true) is not visible in Android N

Tried to show 3 notification in cluster format. As per the doc, I added the setGroupSummary(true) property for the first notification.But in the result i have got only two notification. The notification which is added the GroupSummary property is not visible.
NotificationCompat.Builder firstNotification = createNotification(context,"1.Message","Here you go 1");
firstNotification .setGroupSummary(true);
firstNotification .setGroup("KEY_NOTIFICATION_GROUP");
NotificationCompat.Builder secondNotifi = createNotification(context,"2.Message","Here you go 2");
secondNotifi .setGroup("KEY_NOTIFICATION_GROUP");
NotificationCompat.Builder thirdNotifi= createNotification(context,"3.Message","Here you go 3");
thirdNotifi.setGroup("KEY_NOTIFICATION_GROUP");
Here the notification trigger,
notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0,firstNotification .build());
notificationManager.notify(1,secondNotifi .build());
notificationManager.notify(2,thirdNotifi.build());
And the result is,
I want to show all three notification in the cluster format without missing.
Any help will be really appreciated.
You should check the following answer :
setgroup() in notification not working
You have to create a separate group notification and set the group summary flag true only for that, and that becomes the parent notification that bundles other notifications with the same group key within itself.
setGroupSummary's purpose is to support API levels below Nougat. On Android 7.0 and higher, it shows a normal group and just uses the on click behavior (setContentIntent) and details like the summary text of the summary notification.
On Android 7.0 and lower, it shows your summary notification as a replacement for all the other notifications the group contains.
Android 7 makes a decision regarding summary notification is shown by itself. So, you want see it unless system decides that it needs to be displayed.
Solution: create a dedicated summary notification.

Android Notification- Display full message

My Android Application has to be able to send short alerts out to a large group of people. The obvious place to do this is in the notification center. The full notification shows up in the ticker without a problem, but in the notification center a user can only see the first couple words and then an elipsis. The notifications are not long at all, just 10-15 words at the most. How can I make the text wrap down to a new line?
My code to build the notifications is here
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.splash)
.setContentTitle("Student Engauge")
.setContentText(extras.getString("message"))
.setAutoCancel(true)
.setTicker(extras.getString("message"));
final int notificationId = 1;
NotificationManager nm = (NotificationManager) getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(notificationId, mBuilder.build());
To show large chunk of text, use the BigTextStyle. Here is a sample code as given in BigTextStyle. This notification will one line of text and will expand to more lines if needed.
Notification noti = new Notification.Builder()
.setContentTitle("New mail from " + sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_mail)
.setLargeIcon(aBitmap)
.setStyle(new Notification.BigTextStyle()
.bigText(aVeryLongString))
.build();
For android support library
Notification noti = new Notification.Builder()
.setContentTitle("New mail from " + sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_mail)
.setLargeIcon(aBitmap)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(aVeryLongString))
.build();
For Android 4.1 and later devices, big view is the most suitable solution to show large amount of text. For pre 4.1 devices, you can use custom notification layout to show more data like mentioned here. But you should keep in mind two things:
From the official documentation
Caution: When you use a custom notification layout, take special care to ensure that your custom layout works with different device orientations and resolutions. While this advice applies to all View layouts, it's especially important for notifications because the space in the notification drawer is very restricted. Don't make your custom layout too complex, and be sure to test it in various configurations.
Custom notification layouts have some limitations. Too long texts are not shown fully, but 10-15 words probably fit to the custom layout. This answer has more info about the limitation of custom notification layouts

Android push notification opening a custom page

my question for you is the following: I have a web app written in HTML5, wrapped as a native Android app in order to use Google Push Notifications. Because my app is using many notifications for different reasons, I want to be able to say each time a notification is received, which page to be open, like adding a 'href' in the notification intent. Is this possible?
If I wasn't clear enough please let me know.
Thanks
You can define your own notification message content. The Message builder from Google supports key value pairs to be set by the sender of the notification.
See http://developer.android.com/reference/com/google/android/gcm/server/Message.html
Example:
Message message = new Message.Builder()
.addData("link1", "http://mypage1.com")
.addData("link2", "http://mypage2.com")
.build();
When you create the notification, use setContentIntent() to attach an Intent that has been constructed to visit the right webpage:
// assuming <this> is an Activity or other Context
Intent urlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(yourUrl));
PendingIntent urlPendingIntent = PendingIntent.getActivity(this, 0 urlIntent, 0);
Notification.Builder b = new Notification.Builder(this)
.setSmallIcon(...).setContentTitle(...).setContentText(...) // etc.
.setContentIntent(urlPendingIntent);
NotificationManager noMan
= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
noMan.notify(ID, b.build());
If you expect to have more than one of these in the notification panel at a time:
Reconsider. It's spammy to post more than one notification.
If you must, you'll need a separate ID (or separate tag) for each.

Categories

Resources