GoogleMap snapshot doesn't show in BigPictureStyle Notification - android

So I've been spending couple of days trying to get a Google Map snapshot show up in a notification.
I have come as far as having a working bitmap in my MyGcmListener class (It's viewable from Android Studio when i click the View Bitmap link in the debugger). Now I'm trying to make it appear as a BigPictureStyle notification bitmap, but my luck strikes out. Here is the code:
NotificationCompat.Builder note = new NotificationCompat
.Builder(getApplicationContext())
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(content);
NotificationCompat.BigPictureStyle style
= new NotificationCompat.BigPictureStyle();
style.bigPicture(mapBit);
note.setStyle(style);
note.setAutoCancel(true);
note.build();
note.setContentIntent(resultPendingIntent);
notificationManager.notify(100,note.build());
This will result in a ordinary notification without any bitmaps attached.
Where do I go wrong with this?

So after 2 min refining my search this is the answer:
note.setPriority(Notification.PRIORITY_MAX);

Related

Notification icon not showing properly

I am trying to set a new notification icon for my app, however i cannot seem to make it work. I receive the notifications, but instead of my logo i see a black/grey circle in the status bar like this:
My MessageService looks like this:
public class MyMessagingService extends FirebaseMessagingService {
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Intent intent = new Intent(this, MessageActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("notification_msg_id", remoteMessage.getData().get("my_msg_id"));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder
= new NotificationCompat.Builder(this)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_stat_my_logo)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setColor(getResources().getColor(R.color.colorBlack))
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
I generated the small icon with this (pretty great) tool and as you can see Android Studio is able to find the image in every size needed:
Here's my SDK versions:
I read earlier that there might be some problems with caching of drawables, i've tried invalidating every cache and cleaned/builded the project as well.
I've also tried different image files as well as xml vector drawables.
Do you guys have any idea what i'm doing wrong or how i can troubleshoot the issue further?
Thanks in advance!
Edit:
This is the icon i am trying to use in xxxhdpi-v11 format (it's white you probably need to click it to see it):
you got the same logo name in each folder maybe the one needed by the notifcation is different as notification icon must be of 24x24 dp
Notification icons must be entirely white for API 21 et later. try using this:
notification.setColor(getResources().getColor(R.color.notification_color));

android 7.0 Notification icon appearing white square

I am using the below snippet to generate notifications in my android app.
private void sendNotification(String contentText, String message) {
Intent resultIntent = new Intent(this, MainActivity.class);
resultIntent.putExtra("clear","clear");
resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent piResult = PendingIntent.getActivity(this, 0, resultIntent,0);
NotificationCompat.Builder builder=new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setColor(ContextCompat.getColor(getApplicationContext(),R.color.red))
.setContentTitle("title")
.setContentText(message)
.setAutoCancel(true)
.setLargeIcon(BitmapFactory.decodeResource(getResources()
,R.drawable.notification))
.setContentIntent(piResult);
NotificationCompat.InboxStyle notification = new NotificationCompat.InboxStyle(builder);
int i;
for(i=0; i<messageList.size();i++){
notification.addLine(messageList.get(i));
}
notification.setBigContentTitle("title");
notification.setSummaryText(contentText);
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID,notification.build());
}
It works in android 5 and 6 but for android nougat it is not working
Following the docs from the Android API:
Status bar icons are composed simply of white pixels on a transparent backdrop, with alpha blending used for smooth edges and internal texture where appropriate.
Your whole image but the transparent parts is going to be converted to white (being originally white or having colors).
One solution is to create a silhouette icon with color, by this way you can use the same image in all Android APIs. One example could be this icon:
In lower versions of Android you would see the black face, in the last versions you will see the same face but with white color. That's because of the transparent parts (it seems SO removes the transparency, you can get the original from here) of the image.
From android version lollpop onwards, they have made the changes for the notifications. When you are specifing the small icon, it should be of specific size as mentioned in this link.
The important thing is the image should be transparent and contains only white color.
You can check this question to get the answer
According to this blog here
It says that
You’ll note that the icons are not present in the new notifications; instead more room is provided for the labels themselves in the constrained space of the notification shade. However, the notification action icons are still required and continue to be used on older versions of Android and on devices such as Android Wear.
If you’ve been building your notification with NotificationCompat.Builder and the standard styles available to you there, you’ll get the new look and feel by default with no code changes required.

Weird white expansion in android notification setContent

Trying to implement a custom notification, but I am getting this awful expansion to the notification when i try to forcefully expand it (In my case was not expecting it). This only happens when i switch off screen and then try to interact with the notification other times it acts normal and does not expand when i forcefully try too.
Also tried to cover up the white expansion by setting notification color like below :
.setColor(ContextCompat.getColor(context, R.color.notification_background_light))
did not make much difference.
Testing environment
Device : LG H815
OS : Android 6.0
SNAPHOT :
here
CODE :
builder = new NotificationCompat.Builder(context);
builder.setSmallIcon(R.mipmap.ic_launcher)
.setContent(remoteViews)
.setContentIntent(pendingIntent)
.setColor(ContextCompat.getColor(context, R.color.notification_background_light))
.setOngoing(true);
notificationManager.notify(notification_id,builder.build());
i don't know if its an error from my side.
Thanks in advance

multiline notification in android different behaviour in different device

I am trying to display notification text in multiline.
I am using this code to do so.
NotificationManager mNotificationManager;
String msg = "Do you want to share Fantasy Cricket on Twitter/FB/Google+?";
mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.app_icon)
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText(msg).setAutoCancel(true);
mBuilder.setContentTitle("Change team");
mNotificationManager.notify(notId, 123, mBuilder.build());
It's displaying differently in two devices.
First device
Second device
In first device it just displays fine text in multiline but in second, it's displaying in one line only removing trailing space.
Why it's having different behavior in both. Am I missing something here? Both device are having kitkat if that makes any difference.
UPDATE
As per #leo's answer it will display in two line when there is only single notification. But I checked TOI app it's always displaying in two lines.
TOI's screenshot
Docs say only the top notification is expanded by default. So maybe the other app you are comparing to is using a completely custom notification layout (especially since I don't see a title there)?
In case someone falls into it like me, so according to LINK
Users can drag down on a notification in the drawer to reveal the expanded view, which shows additional content and action buttons, if provided. This happens often on Samsung devices though...

How to display timestamp in Android Notifications for Honeycomb+ devices?

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.

Categories

Resources