I am trying to set an alarm notification icon in the Notification
Area doing this:
Notification notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_notify)
.setCategory(CATEGORY_SERVICE)
.setContentTitle("Service")
.setContentText("Alarm is ON").build();
I made my icon in Android Studio using File -> New -> Image Asset -> "Notification Icon" then choosing a pre-defined clip-art.
The strage thing is, in the Notification Drawer I get the ic_launcer icon
and in the Notification Area I get the trange "oo" icon you can see on the
left side of the image below.
picture of my Notification Area
Have you every seen this? Do you know how to fix it? The phone on which
I am testing is a Meizu U20, Android 6.
Related
I use below code to display notifications in my Android apps. I can display it but both "small-Icon" and "large-Icon" are incorrect.They are not even launcher-icon.! I don't know Android where does they get from !!!!
My device is xiaomi-mi5s, is it related to my device? although other apps like Gmail show correct notifications.
I tested notifications in API 15,17,26 emulators and everything
NotificationCompat.Builder builder = new android.support.v4.app.NotificationCompat.Builder(context, PRIMARY_CHANNEL)
.setSmallIcon(R.drawable.ic_stat_name)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
.setContentIntent(getPendingIntent(context))
.setContentTitle("This is dummy title")
.setContentText("This is dummy body text")
.setSound(getDefaultSoundUri())
.setCategory("My_Category")
.setDeleteIntent(getOnDismissedPendingIntent(context));
NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= 26) {
NotificationChannel chan1 = new NotificationChannel(PRIMARY_CHANNEL,
PRIMARY_CHANNEL, NotificationManager.IMPORTANCE_DEFAULT);
chan1.setLightColor(Color.BLUE);
chan1.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
manager.createNotificationChannel(chan1);
}
manager.notify(12121, builder.build());
First of all, Large icon and Small icon can be different.
setSmallIcon(): sets an icon that should be displayed at status bar when notification was received. If setLargeIcon() was not called in the builder, large icon will use small icon drawable. Icon should have size of 24dp.
setLargeIcon(): sets an icon that should be displayed at notification in notification list, that can be opened by user by vertical dragging of status bar.
!!! Since API 21, Android requires you to use only single-colour icons with transparency for small icons (e.g. filled contour of Android with only white colour and transparent background).
As a Large icon, you can use icon of any colours, there are no restrictions.
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
I have a static Array with Icon ids:
public static final int[][] ICON_IDS = { {R.drawable.ic_access_alarm_black_24dp, R.drawable.ic_access_time_black_24dp, R.drawable.ic_account_box_black_24dp, R.drawable.ic_add_black_24dp, R.drawable.ic_android_black_24dp, R.drawable.ic_clear_black_24dp, R.drawable.ic_delete_black_24dp },
{ R.drawable.ic_settings_black_24dp, R.drawable.ic_airplanemode_active_black_24dp, R.drawable.ic_filter_list_black_24dp, R.drawable.ic_account_box_black_24dp, R.drawable.ic_airline_seat_individual_suite_black_24dp, R.drawable.ic_delete_black_open_24dp, R.drawable.ic_delete_black_open_24dp}};
I display all the icons and the user can choose one. The id of the chosen icon is passed to the notification manager. It displays the notification like this:
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(notification.getIconId())
.setContentTitle(notification.getTitle());
I have checked with an "test-ImageView" that the id is correct. The ImageView displays the icon the user selected (with setImageResource(notification.getIconId());). But on the notification in the notification bar another icon is displayed or none.
If I use .setLargeIcon() it shows the correct icon again.
.setLargeIcon(BitmapFactory.decodeResource(getResources(), notification.getIconId()))
But only in the big icon. The small icon is empty.
The icons are the material icons imported via vector assets.
What is wrong with this?
Found out why. You can't use xml resources as Notification Icons.
My app receives a Notification, the sound is heard, the little icon is shown, however the status text is not shown.
Up until Marshmallow i did not face this issue, weird..
I use the SetTicker method to set the status bar text property into the Notification.Builder object.
this is my code:
Notification.Builder nb = new Notification.Builder(GCMIntentService.this);
nb.setSmallIcon(mSmallIconRes)
.setContentTitle(mContentTitle)
.setContentText(mContentText)
.setStyle(new Notification.BigTextStyle().bigText(mContentText))
.setTicker(mTicker)
.setLargeIcon(result == null ? mDefaultLargeIcon : result)
.setSubText("")
.setContentInfo(mContentInfo)
.setWhen(mWhen)
.setSound(alarmSound);
Assuming you just want to add some text on the second line about the status try adding .setContentText("You're text here")
More info can be found here
http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setContentText%28java.lang.CharSequence%29
EDIT:
Apparently 'As of the L release, this text is no longer shown on screen' so that may be why you're having an issue here
Is there any tutorial about how to design a good icon to put in the status bar as a notification in an Android App?
Ideally I'm looking for a template or an icon that I can easily modify. I'm not a designer.
I need smiley faces status bar icons.
You can download icons from the buzzbox sdk resources page:
http://hub.buzzbox.com/android-sdk/notification-icons
there is also a photoshop file you can download and modify.
There is also one simple status bar template icon in the official template pack from Android
http://developer.android.com/guide/practices/ui_guidelines/icon_design.html#templatespack
Here is the information straight from the Android Developer's Page: http://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar.html
This also contains a link to the icon template pack
Check out the Android Asset Studio! It's a great tool for creating a number of Android icons, including notification icons.
Notification notification = new Notification(R.drawable.asterisk_sign, text, System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); //this is how we will launch an Activity when the user clicks the notification
notification.setLatestEventInfo(this, getText(R.string.app_name), text, contentIntent);
mNM.notify(R.string.minutemaid_service_started, notification); //send the notification to the system, to be displayed in the notification bar
this is an example of how to make a notification in the notification bar that starts an activity when selected.