The expanded notifications introduced in Jelly Bean allows adding actions. The actions appear as buttons in a row. If I wanted to modify this with my own custom view I would consider a remoteview.
Do expanded notifications allow for remoteviews? I can only find examples of remoteviews being used in simple notifications before the expanded notifications existed.
It appears that http://codeversed.com/expandable-notifications-android/ has the answer in the Custom View at the end.
So what if the rich notification styles don’t provide you with the
layout you need? Easy, just create your own layout and pass it to the
builder. One little fact to retain is that notifications use remote
views, which means you need to create a layout using a RemoteView.
Below is exactly how you would need to create this custom RemoteView.
notification.bigContentView = expandedView;
Related
Trying to create android notifications with a custom body provided by an XML file.
When I try to set the title of these notifications, it does not appear.
Oddly, the subtext continues to show just fine.
Showing a standard notification (no CustomContentView), and
builder.setContentTitle("foo");
builder.setSubText("bar");
// builder.setCustomContentView(customNotificationView);
Both the title and subtext show.
If I set it to use a custom view, the title disappears. (and instead shows app name)
builder.setContentTitle("foo");
builder.setSubText("bar");
builder.setCustomContentView(customNotificationView);
Am I missing something? Does Android just not use ContentTitle when you have any kind of CustomView?
I assume what's happening is that the 'content' title is getting removed because we're replacing the 'content' with a new view.
Is there any way to give a notification with custom content a "native" title? (instead of adding text inside the RemoteView that we treat as the title).
misc notes
using AndroidX versions (import androidx.core.app.NotificationCompat;)
The title is removed whether or not I add a decorated style (.setStyle(new NotificationCompat.DecoratedCustomViewStyle());
The title is removed whether or not I set the custom view via .setContent or .setCustomContentView
Yes, you're right! setContentTitle is part of basic notification. builder.setCustomContentView(customNotificationView) is custom notification with custom layout and custom data which you can pass inside. Of course you can do more with custom notifications but I think the freshest version of Android kills all magic of customization. For example if you have targetSdkVersion 31+ then you cannot change background of notification on Android 12+ devices :(
I have managed to create this kind of notifications
following this guide: http://developer.android.com/training/notify-user/expanded.html#big-view
However I cannot find any documentation on how to achieve this style:
How can I do this?
As described in Custom notification layouts, you can set a custom content of the notification with Notification.Builder.setContent(RemoteViews)
You need to add custom notification layout and through the remote views.
http://developer.android.com/guide/topics/ui/notifiers/notifications.html#CustomNotification
https://stackoverflow.com/a/18414768/713778
I'm currently creating a custom status bar notification to notify the user of progress through an event. I have the custom notification working fine, but having a progress bar requires that I pass my own set of RemoteViews to the notification through the contentView field.
This is fine, except that I want to be able to base this layout off the default one. I am targeting API 10, and so it must work with both Gingerbread and ICS. Gingerbread is fine, as I can just put an icon on the left of the layout and the notification fits in with other default ones. In ICS however, the notification icons all have the striped square on the left that contains the icon (it effectively forms a UI "handle" to help indicate that the notification can be swiped to dismiss it).
Does anyone know how I can either get the default layout in code, and then edit it (this is hard with remoteViews), or somehow get access to default layout view (probably during runtime), then copy it, and substitute the notification text for my progress bar?
I have seen examples where people have created a notification and cloned the layout, but to do anything useful with that you have to know quite a lot about the layout. I would rather get the layout files from the android versions you are interested in. Here you have the JB one, you should not have any problems finding the others.
If the only reason you want a custom layout is to get a progress bar, you could look at
NotificationCompat.Builder.setProgress(). It'll be easier than playing with custom notification layouts. If you do decide to use custom layouts, they changed only slightly between API v14 and API v17, and I have no idea what they're like for Honeycomb but they're unlikely to be much different. What that means is that you should be able to use one custom notification layout in a layout-v11 folder, and one in your default layout folder, and you'll catch most cases (except for the icon background from Honeycomb upwards, I haven't gotten that part working in my own custom notifications yet) and only have to maintain two different layouts. See the answer above for the location of the default layout; note that it's called status_bar_latest_event_content.xml in earlier versions of Android.
Since setProgress() is available from Honeycomb upwards at least, and it looks like it works on earlier versions too (the docs don't say otherwise), then you should probably use that if you don't have any other custom requirements.
I'm trying to create a custom notification layout that looks just like a 3.0 notification, with a couple of extra things sprinkled in. More importantly, I also want to derive a Jelly Bean expanded notification on top of that.
I'd like the notification to have the same layout as a stock notification so it fits in nicely, i.e. like this (bottom image):
However, I cannot find any information about the proper dimensions and styles - what size do I need to use for the image on the left? What style for each text? What padding?
Ideally, I'd love to use something like android.R.listPreferredItemHeight for the height of the layout and the dimensions of the image, but I can't find anything that pertains to notifications.
You can use the Notification.Builder class which provides a convenient way to set the various fields of a Notification and generate content views using the platform's notification layout template.
See: http://developer.android.com/reference/android/app/Notification.Builder.html
If you need to be compatible with versions prior to API level 11 then take a look at the NotificationCompat.Builder from the support library.
I want to change default android notification view. Can I make height of Custom Expanded View more than 3 lines of text?
Check this article on how to make custom notifications using your own layout. If this helps you already: good. If not: The RemoteView also offers options to create custom notifications, so it might help you. Alternatively you could create multiple notifications if the number of lines is really limited (which I am not sure of).