How to add an icon on a peeking custom android wearable notification? - android

Our custom notification only shows title (or content text if title is missing) when it's peeking. Trying to set the icon on the root notification has no effect. If I set the icon on the extender notification it shows, but the peeking notification is so small (obviously, its height is fitted to the height of the one liner title/description) that the icon wont fit. In comparison to e.g. an email notification the height of the peeking notification is much smaller.
Here's the outline of the code I'm trying to run:
Intent notificationIntent = new Intent(this, CustomNotification.class);
PendingIntent notificationPendingIntent = PendingIntent.getActivity(this, 0,
notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification.Builder(this)
.setContentTitle("Test")
.setSmallIcon(R.mipmap.ic_launcher)
.extend(new Notification.WearableExtender()
.setDisplayIntent(notificationPendingIntent)
.setCustomSizePreset(Notification.WearableExtender.SIZE_FULL_SCREEN)
)
.build();

You may be running into that fact that you have very little control over how the notification displays while in peek-view:
"Note: When the notification is peeking on the homescreen, the system displays it with a standard template that it generates from the notification's semantic data. This template works well on all watchfaces. When users swipe the notification up, they'll then see the custom activity for the notification."
https://developer.android.com/training/wearables/apps/layouts.html#UiLibrary

Related

Android removing notification data in group notification when new notification is added to the group

My group notifications are working fine, however, I noticed that after a couple of hours (When not using the device for a while) when a new notification comes, the message content disappears when the notification is expanded, that is, setStyle(new NotificationCompat.BigTextStyle().bigText()) text disappears. I know it is not a request code issue, as all request code are unique and I am able to reply to the notifications as normal.
One thing to note, after the notification disappears, the next notification that comes, if the device is active (not necessarily the app), that notification will display its normal text when expanded. This seems to occur only when the device AND/OR App is not in use for a while. Is this an android system problem?
Below is picture snap shot to describe the behavior:
First notification
Second notification comes in.
Expanding both notifications, as you can see all of the messages for both of them disappears.
Code: Note that I only send summary notification once.
// Normal notification
int uniqueRequestCode = RandomUser.getUniqueRequestCode();
PendingIntent pendingIntent = PendingIntent.getActivity(
this, uniqueRequestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Notificatio notification = new NotificationCompat.Builder(getApplicationContext(), MESSAGE_CHANNEL_ID)
.setSmallIcon(R.drawable.ne1_white_logo_crop)
.setContentTitle(title)
.setContentText(body)
.setStyle(new NotificationCompat.BigTextStyle().bigText(body))
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
// Set the intent that will fire when the user taps the notification
.setContentIntent(pendingIntent)
.addAction(action)
.setGroup(GROUP_KEY_MESSAGE)
//.setGroupAlertBehavior(groupAlert)
.setColor(Color.BLACK)
.setAutoCancel(true)
.build();
// Summary notification
uniqueRequestCode = RandomUser.getUniqueRequestCode();
PendingIntent pendingIntent = PendingIntent.getActivity(
this, uniqueRequestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification summaryNotification = new NotificationCompat.Builder(this, MESSAGE_CHANNEL_ID)
.setSmallIcon(R.drawable.ne1_white_logo_crop)
// Specify which group this notification belongs to
.setGroup(GROUP_KEY_MESSAGE)
// Set this notification as the summary for the group
.setGroupSummary(true)
.setContentIntent(pendingIntent)
.build();
According to this stack overflow answer, Android by default only allows one notification to be expanded.
What I have been using now which is sufficient, and preserves expanding notification is .setStyle(new Notification.MessagingStyle.... I highly advise using MessagingStyle for situations where you want multiple notifications in a group to be expanded. As for BigTextStyle().bigText(), I am not sure of the proper procedure, so I have abandoned it.

Notification size when not showing first

I'm using local notification like clock alarm with buttons to control it. My problem is that the Notification view isn't wrapping my content. So after searching around I found out that there is a workaround to achieve this by setting the view after build.
Something like this:
Notification notification = mBuilder.build();
// add remote view after build for getting bigger notification size
notification.bigContentView = remoteViews;
This work unless the notification is not first and when it is not the top notification the buttons is not shown.
How can I make the notification wrap_content even when it is not the top on the list of notifications?
Set the priority Max for notification for showing big content view like below
new Notification.Builder(this)
.setContentTitle("Media Player")
.setContentIntent(mPendingIntentHomeSong)
.setSmallIcon(R.drawable.app_icon)
.setPriority(Notification.PRIORITY_MAX)
.setContent(mNotificationContentView)
.setStyle(new Notification.BigPictureStyle()).build();

Can we do a custom layout for notification on android wear project

I have Created a project for android wear devices.
I need to customize the notification style on the wearable device. Is there any method for that.
My method is
Intent displayIntent = new Intent(getApplicationContext(), CustomNotification.class);
PendingIntent displayPendingIntent = PendingIntent.getActivity(getApplicationContext(),
0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification =
new NotificationCompat.Builder(context)
.extend(new WearableExtender()
.setDisplayIntent(displayPendingIntent))
.build();
int notificationId = 001;
// Get an instance of the NotificationManager service
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(this);
notificationManager.notify(notificationId , notification);
But i didn't get a notification.
Is there any method to customize with my custom layout design?
and this is the manifest part
<activity android:name="com.client.android.CustomNotification"
android:exported="true"
android:allowEmbedded="true"
android:taskAffinity=""
android:theme="#android:style/Theme.DeviceDefault.Light" />
Please take a look at the official documentation about creating custom notifications on Android Wear.
Use Big View:
You can apply styles to your notificaitons, such as BigPictureStyle, BigTextStyle or InboxStyle.
Here is an example of using BigTextStyle:
// Specify the 'big view' content to display the long
// event description that may not fit the normal content text.
BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
bigStyle.bigText(eventDescription);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_event)
.setLargeIcon(BitmapFractory.decodeResource(getResources(), R.drawable.notif_background))
.setContentTitle(eventTitle)
.setContentText(eventLocation)
.setContentIntent(viewPendingIntent)
.addAction(R.drawable.ic_map, getString(R.string.map), mapPendingIntent)
.setStyle(bigStyle);
More info:http://developer.android.com/training/wearables/notifications/creating.html#BigView
Use custom notification layout:
You can create a layout in your Activity and embed it inside your notification:
https://developer.android.com/training/wearables/apps/layouts.html#CustomNotifications
NOTE: Please notice that this approach has some restrictions and will only work for notifications submitted directly from Android Wear device (not from phone).
Please also read the note at the end of that tutorial:
Note: When the notification is peeking on the homescreen, the system displays it with a standard template that it generates from the
notification's semantic data. This template works well on all
watchfaces. When users swipe the notification up, they'll then see the
custom activity for the notification.

How to create notification with statusbar text(no icon)

I am creating one notification application.
But application require text instead of icon/image.
Reference image:http://tinypic.com/view.php?pic=23hu5xd&s=6
I am using this way to create notification all of the work fine but require text on status bar.
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("hiii") // title for notification
.setContentText("Hello word") // message for notification
.setAutoCancel(false); // 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);
mNotificationManager.notify(0, mBuilder.build());
Problem:
how to set text instead of image. setSmallIcon(R.drawable.ic_launcher)
You have no choice but to set an image. You are welcome to have the image contain text.
In the screenshot you cited, the app probably has ~100 images to choose from for different percentage levels. You can organize those into a single LevelListDrawable, then use the two-parameter version of setSmallIcon() to indicate which level you want.

How to use bigTextStyle in android 4.1 notification?

I tried in many ways to get the long thext styled notification but just cant reach my goal, pls someone help.
I would like to use bigTextStyle in order to get multiline message in my notifs. Here is my code:
mNotificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, new Intent(ctx, MainActivity.class), 0);
Notification noti = new Notification.Builder(ctx)
.setContentTitle("Title")
.setSmallIcon(R.drawable.ic_launcher)
.setStyle(new Notification.BigTextStyle().bigText(ctx.getResources().getString(R.string.loremIpsum)))
.setContentText(ctx.getResources().getString(R.string.loremIpsum))
.setContentIntent(contentIntent).build();
mNotificationManager.notify(NOTIFICATION_ID, noti);
I use Android 4.1.2 so the op version is ok. Every notificaion is a simple one-lined message, and i dont see the whole text. Please help me.
E D I T:
Okay i got the long text, but my notif not expanding automatically, i have to swipe down with 2 fingers. How could i expand it by code..!?
You have to expand the notification to see the big text - by default only the top notification auto-expands, as described in the Notifications guide.
Maybe your notification is getting collapsed because ongoing notifications are eating up the screen space. See my answer here: Android Jelly Bean strange behavior of notifications.
even if u set the MAX priority to push your notification to the top
or it was the only notification in the notification drawer
it wont expand if there is no enough space
e.g.
to many "Ongoing-notifications" in the "Ongoing"Drawer or your screen is small
and even if it was expanded it wont show more than 8 lines , so not all the notification will shows up

Categories

Resources