I have a notification on the handheld with a big text style:
notif.setStyle(new NotificationCompat.BigTextStyle()
.bigText(bigLine).setBigContentTitle(titleLine));
This causes the corresponding Wear notification to have this extended text on the first page.
Is there any way to change what is shown on the first page for the wearable only, while leaving the handheld notification unchanged?
In the end, I'd like to split out the bigText value into pages for the wearable.
If you want to split the text from your notifications into few pages - it seems like you have few "items" in one notification and want show them separately on wearable device. If you really have such scenario you should consider using the grouping functionality
This feature is used for example in Gmail app. You basically have one group notification (but with InboxStyle instead of BigTextStyle) on your mobile and multiple notifications on wearable device within one group.
Group notification
You need to set the same groupKey for all these notifications by using method setGroup (String groupKey)
and then use method setGroupSummary (boolean isGroupSummary) with true value to ndicate which one is a summary notification and should be displayed only on mobile. A non-summary notifications will show up only on wearable device.
Two grouping approaches
Using this approach you can submit one notification (group summary notification) on your phone and multiple notifications on the wearable that will be displayed as a one group. So you will end up with something like
MOBILE: 1 group summary notification
WEAR: X notifications within a group
But if you really want to have one notification with X pages instead of X notifications you can work it around in following configuration:
MOBILE: 1 group summary notification
WEAR: 1 notification "within a group" with X pages
Related
I am triggering local push notifications based on need from app itself.I am using inboxStyle for my notifications to contain large text lines, and that is showing perfectly fine.Here is android OS makes the top one notification expanded by default and all I need to know is how to collapse all my notifications by default. Thanks
I have implemented push notifications via PushApps.
My requirement is that, if user get multiple notifications then i need to show as a single notification with number of notifications counts.
PushManager.getInstance(getApplicationContext()).setShouldStackNotifications(false);
Grouping is working fine with above line but number of notification count are not displaying.
Please suggest me something.
Thanks.
Basically, I am wondering if it is possible to create two different notifications and how - one for Android Device and other for Android Wear?
For example: I want to have just setContentText, but on Android device I want setContentTitle and setContentText
There is currently no possibility to show notification just on Wear (like setLocalOnly with device only - look for more).
I think the Synchronized Notifications sample that comes with the Android Wear SDK may be useful to look at. It gives three simple types of notifications:
(1) A phone-only notification
(2) A watch-only notification
(3) A pair of synchronized phone and watch notifications where the content shown
on the watch notification is different from the one on the phone. They are
synchronized in the sense that dismissing one results in dismissal of the
other one; all based on the Data Layer apis.
I think the third use case is most relevant to you.
Officially it is not possible to create two different notifications for wear and the phone without writing your own Android Wear App extension. It is only possible to define a notification that is only shown on the phone with NotificationCompat.Builder.setLocalOnly(true)
To create a Notification that is only shown on a Wear Device however you can (at the moment) add the Notification to a group with NotificationCompat.Builder.setGroup(randomGroupKey) and omit the display of a group summary notification. If a notification belongs to a group it is not displayed on the phone because the phone will only show the summary notification. If there is no summary you get a notification for your watch only. Just generate a random group key for every watch only notification.
Officially it is only possible to create a notification that looks different on a smartwatch.
For this use a WearableExtender. For example this code snippet:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle(getString(R.string.smaple_notification_title));
builder.setSmallIcon(R.drawable.ic_message);
builder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, ActivateActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));
NotificationCompat.WearableExtender extender = new NotificationCompat.WearableExtender();
extender.setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.notif_background));
extender.setContentIcon(R.drawable.ic_message);
extender.setHintHideIcon(true);
extender.extend(builder);
builder.setPriority(NotificationCompat.PRIORITY_LOW);
builder.setContentText(notificationText);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.large_icon));
notificationManager.notify(messageIndex, builder.build());
Sets a special background for the notification, hides the app icon that is normally displayed on the notification, and adds a new icon to the preview of your Notification in the "screen off" mode of the watch.
I don't know if there is a way to do exactly what you want but I try to use stack & summary to bypass this: an contentText only notification has been hidden by a summary notification with contentText and contentTitle. On the Android Wear however summary is not being displayed but all the stacked notification (in your term is the notification with only contentText) can be shown.
Yes, It is possible. Steps -
Intercept your Notifications on Handheld by implementing BroadcastReceiever
Generate Notification for Handheld using NotificationBuilder - use setLocalOnly to duplicating it with Wearable
Send Notification data in Message to Wearable - using MessageApi
Extract receieved data & generate Notification for Wearable
In my app I am applying push notifications and making them using the notificationCompat class.
I am assigning each notification a unique ID therefore, each one is visible seperately in the notification bar.
When the user clicks on a notification, using a pending intent, I am directing the user towards a certain activity, where he can see all the previous notifications. ( I read them from mysql db ).
question 1 : I want all the notifications in the status bar get cleared if the user clicks only on one of them. Can be a any random one (given it is from my app). the setAutoCancel() method, only removes the one pressed, and I cant seem to know where I would implement the cancelAll() method.
Answer :
#Override
protected void onResume()
{
super.onResume();
NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
}
question 2 : Since each notification has unique ID, sending several notifications from an individual app, and in case of not checking from the user, might result in several icons to appear in the notification bar. Android, starts collecting them and showing badge numbers on them once they start taking too much space and the system realizes there is no enough space for them.
Is there any method to combine them all from the beginning ? That is, whenever I send a notification, and it is not checked, the second one should be added and a single icon should appear on the bar with the number 2 or + , whatever the system uses.
I'd like to combine question 1 and 2 into a single answer: Do not show multiple notifications! Show one notification and update it when you have more than one unchecked notification. As a user I would get really annoyed if my notification bar was spammed with notifications from a single app. Think of the GMail app and it's notifications if you would get one per incoming e-mail.
On pre 4.1 devices you'll have to make do with the Normal View. If you have only one unchecked message you could show the contents of the message immediately in the notification, and if you have more than one you could do something like the GMail notification and show something like "5 unchecked messages".
On 4.1+ devices you can use the Big View to show all of them at once.
I'm Navis, I come from VietNamese and I'm a newbie in android developer.
When i make an application i have a problem with Notification in android.
I used C2DM service to integrate push messages for my app. And when receive message from C2DM server, i want my app show information in notification separated. 1 message show in 1 notification. But when i test app, i push message to my android devices, it only show 1 notification. For example, i push 3 message (1, 2, 3). App will display 1 the same position (only update content). So, how can i display in 3 notification separated?
Thanks for your help!
My guess is that you are passing the same id to notify api.
Change the ID to different one to show different notifications instead of replacing
mNotificationManager.notify(_ID, notification);