I'm using a Custom View for notifications.
In this case, I know that for a big size notification, I have to use bigContentView and set a big view for it.
Every thing is good in API 16, But my app minimum SDK is API level 10 and bigContentView is not supported in API level 10.
myNotification= notification.setContentTitle("some string")
.setContentText("some text")
.setSmallIcon(R.mipmap.ic_launcher)
.build();
RemoteViews notificationView = new RemoteViews(MyApp.getAppContext().getPackageName(),
R.layout.custom_notification_layout);
myNotification.bigContentView=notificationView; //Error in this line!
Is there another way to display big layout for a custom notification?
Or is a older version of bigContentView?
Big view for notifications were introduced in and android 4.1 and they're not supported on older devices. (as #Pop Tudor commented)
We can use it by bigContentView(RemteView) for notifications if api level is upper than 15.
In API 15 or lower, we can only set custom view for notifications by contentView(View) method.
Related
Surprising my APP's icon comes up with white color icon in notification bar on my Nexus 5. This is only in Nexus 5.
There is a question already about this the answer shows I need have: target 20. Which I have tried already: Like below no difference.
defaultConfig
{
applicationId "com.cn.redquest"
minSdkVersion 20
targetSdkVersion 20
versionCode 10
versionName "1.00"
}
Can somebody help me fix this?
Let me know!
Thanks!
Setting the target SDK to 20 means that you do not build your app for Android Lollipop. This will make your notification icon display all colors, but is not a long-term solution, since you will want to build for Lollipop (at least eventually).
At http://developer.android.com/design/style/iconography.html you can read about that the white style is how notifications are meant to be displayed in Lollipop (SDK 21). Google also suggests using a custom bg color - https://developer.android.com/about/versions/android-5.0-changes.html
I think a better solution is to actually provide the system with a silhouette icon, if the device is running Android Lollipop.
For instance:
Notification notification = new Notification.Builder(context)
.setAutoCancel(true)
.setContentTitle("My notification")
.setContentText("Look, white in Lollipop, else color!")
.setSmallIcon(getNotificationIcon())
.build();
And, in the getNotificationIcon method:
private int getNotificationIcon() {
boolean useSilhouette = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
return useSilhouette ? R.drawable.ic_silhouette : R.drawable.ic_launcher;
}
I am adding two buttons to a notification in my app that is set to target API Level 8. The problem is that the two buttons appears as two large grey buttons, totally out of place with the rest of the notifications. I've tested it both on Nexus 7 and Galaxy Nexus.
All examples I've seen have the nice looking black buttons like the incoming call notification:
http://www.androidng.com/wp-content/uploads/2012/07/android-jelly-bean-notifications.jpeg
I would guess this would be easy, but no such luck today. Does anyone know where I might have taken the wrong turn? Below is a snippet of my code which generates the notification with the latest support library.
NotificationManager nm = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
android.support.v4.app.NotificationCompat.Builder builder = new android.support.v4.app.NotificationCompat.Builder(this);
builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_stat_radio)
.setContentTitle(message)
.setTicker(message)
.setPriority(android.support.v4.app.NotificationCompat.PRIORITY_HIGH)
.setWhen(System.currentTimeMillis())
.setAutoCancel(false)
.addAction(android.R.drawable.ic_btn_speak_now, "Play", contentIntent)
.addAction(android.R.drawable.ic_dialog_map, "Stop", contentIntent)
.setContentText(message);
Notification n = builder.build();
//nm.notify(0, n);
startForeground(1, n);
So this is happening because your targetSdk in your AndroidManifest.xml is < 11.
I believe the change in compatibility that happens when you target 11 is that the default theme because Holo. Since yours (and my) target is less than 11, it's resorting to some compatibility theme that it applies on these buttons even though it shouldn't. I assume that even though your app / activity is set to Holo, it doesn't actually apply to the notification since they are are in a different process.
That's just my guess. Using CommonsWare's notification demo and just modify the targetSdk shows this behavior.
Im having the same issue, using Android studio (0.8.11) with Gradle (0.13.0)
compileSdkVersion 20
buildToolsVersion "20.0"
defaultConfig {
applicationId "x.xx.xxxxxx"
minSdkVersion 10
targetSdkVersion 20
versionCode x
versionName "x.xx"
}
Solve it by adding uses-sdk to the Manifest
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="20" />
I know the Manifest value will be overridden by Gradle value. but that solve it.
I'd like to show a timestamp in an Android Notification, just like the Android Design Guidelines suggest. (see the first snapshot, "12:03PM" is what I want!).
I tried many different ways, I thought setWhen would do it, but it only seems to affect the ordering in the Notification tray. Any idea how to achieve that?
See my code below:
Notification.Builder builder = new Notification.Builder(context);
builder.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_notify)
.setLargeIcon(largeIcon)
.setTicker(text)
.setNumber(unreadCount)
.setWhen((new Date()).getTime())
.setAutoCancel(true)
.setContentTitle(title)
.setContentText(text)
.setDefaults(Notification.DEFAULT_VIBRATE);
notificationManager.notify(NOTIFICATION_ID, builder.getNotification());
I don't want to use a custom layout for the notification.
I think I found the answer myself, when seems to be displayed only on Android 4.0.3 and later.
My wife's Nexus S (4.0.3) shows it, and I just upgraded to 4.0.4 on my Galaxy Nexus and it magically started to work!
It also shows on older versions (2.3 for instance), but not on 4.0.2 !
Use setContentInfo and pass your date as a string into it.
From this link
public Notification.Builder setContentInfo (CharSequence info) Since: API Level 11
Set the large text at the right-hand side of the notification.
Large Text at the right hand side of the notification should be where you want to put time.
Also from the same link:
public Notification.Builder setWhen (long when) Since: API Level 11
Set the time that the event occurred. Notifications in the panel are
sorted by this time.
which means that setWhen only sorts the notifications, and doesn't set any text.
In the bottom right corner of a standard Android notification is time (eg 12:00). Can I hide it without using custom notification layout?
For API level 17 and onward, the above accepted answer by Erwan is correct.
For historical purposes, the answer below remains
It is possible to do that.
Try setting when to 0.
For the few notifications that don't do that, it looks like thats what they do.
Here's the general API reference.
Here's a link to the ADB notification and search for private void updateAdbNotification()...
From API Level 17 onwards, you can use setShowWhen(false)
public Notification.Builder setShowWhen (boolean show)
Added in API level 17 Control whether the timestamp set with setWhen
is shown in the content view.
http://developer.android.com/reference/android/app/Notification.Builder.html#setShowWhen(boolean)
For API level 17 and onward,
mBuilder.setShowWhen(boolen);
1.Use Hide Notification Time
mBuilder.setShowWhen(false);
2.Use Show Notification Time
mBuilder.setShowWhen(true);
Is there any way to use an image that I'm generating on the fly as a Notification icon?
This topic was discussed in a previous SO question. Upshot: I don't think it is possible.
UPDATE: For tablets or other large-screen devices, on API Level 11+, there is a largeIcon property which accepts a Bitmap. AFAIK, this is unused on smaller-screen devices, such as phones.
You can now change the main icon with API 11 (Notification.Builder -> setLargeIcon)
Try creating a custom Notifications view, then you should be able to use a Bitmap object:
RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.custom_notification_layout);
contentView.setImageViewBitmap(R.id.icon_view, myBitmapObject);
notification.contentView = contentView;
For more info see "Creating a Custom Expanded View" on this page: https://developer.android.com/guide/topics/ui/notifiers/notifications.html