I'm about to publish my first application. I created all the necessary icons, in my case the launcher icons and the status icons (which I only created for my app next versions updates).
But I am wondering where the status icons names are set. I mean, the launcher icon name is set in the Manifest file this way :
android:icon="#drawable/ic_launcher"
so is there a similar place to set the status icon name?
Thanks in advance!
I'm pretty sure you explicitly set the icon when you make a notification. So:
int icon = R.drawable.notification_icon;
CharSequence tickerText = "Your Text";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
This was taken directly from http://developer.android.com/guide/topics/ui/notifiers/notifications.html
Related
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.
I've a problem with the notification icon in android .
this is my code :
Notification myNotification = new NotificationCompat.Builder(ctx)
.setSmallIcon(getNotificationIcon())
.setAutoCancel(false).setContentTitle(onvan)
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
.setContentIntent(pending).build();
long number = (long) Math.floor(Math.random() * 9000000000L) + 1000000000L;
notificationManager.notify((int) number, myNotification);
private int getNotificationIcon() {
boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
return useWhiteIcon ? R.drawable.ic_launcher : R.drawable.ic_launcher;
}
What is the problem ?
Post android Lollipop release android has changed the guidelines for displaying notification icons in the Notification bar. The official documentation says "Update or remove assets that involve color. The system ignores all non-alpha channels in action icons and in the main notification icon. You should assume that these icons will be alpha-only. The system draws notification icons in white and action icons in dark gray.” Now what that means in lay man terms is "Convert all parts of the image that you don’t want to show to transparent pixels. All colors and non transparent pixels are displayed in white"
You can see how to do this in detail with screenshots here https://blog.clevertap.com/fixing-notification-icon-for-android-lollipop-and-above/
Hope that helps
This is for a general notification app. I've managed to capture and set the large icon for the notification since it accepts a Bitmap type as a parameter, but setting the small icon is proving to be a lot more tricky. It only accepts an int resource ID. Since I have no idea what application might be sending a notification to my listener, I would have to generate it dynamically. I can get the small icon by listening for incoming notifications and extracting it, but I can't seem to find a way to set it via its resource ID.
I don't think it's possible, but just want to confirm. If so, is there a workaround, or would I have to manually load small icons of specific apps I want to support into my Drawable folder and then use the resource Id from there? That sounds like a hassle seeing that I've already gotten the right icon, but can't load it in! Below is my code:
public class NotificationService extends NotificationListenerService {
#Override
public void onNotificationPosted(StatusBarNotification sbn) {
Bundle extras = sbn.getNotification().extras;
int id1 = extras.getInt(Notification.EXTRA_SMALL_ICON);;
//Building Notifications
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context.getApplicationContext(id1))
.setSmallIcon(R.mipmap.ic_launcher) //This gives an error
.setContentTitle("My Title")
.setContentText("My Text");
NotificationManager notificationManager =
(NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notiId, mBuilder.build());
}
}
Small icon might not load if it exceeds the size prescribed by Android.Generally we can load small icons through images stored in resource folder only.
can get the details regarding icon sizes for push notifications from the following link
GCM Push Notification Large Icon size
Small Icons in push notifications cannot be added dynamically. Large Icons can be added dynamically by running an Async task. Application will crash if there is no small icon. Small Icon is mandatory for PushNotification.
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.