I am currently working on an android project and I am trying to create a notification from a standard java class (not an activity class).
I’ve added a icon into the drawable folder called icon.png but when I try and set the icon to an int using R.drawable.icon icon never shows up only the default built in android icons.
I don’t understand why it is not showing my own icons.
Thanks for any help you can provide.
UPDATE
As requested below is the code for setting up the notification
private void showNotification(String username, String password)
{
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager = (NotificationManager)context.getSystemService(ns);
CharSequence tickerText = "Username Copied";
long when = System.currentTimeMillis();
int icon = 0;
Notification notification = new Notification(icon, tickerText, when);
CharSequence contentTitle = "BPM - Login Management";
CharSequence contentText = "Username Copied";
Intent intentNotification = new Intent();
intentNotification.setAction(Long.toString(when));
notification.flags |= Notification.FLAG_AUTO_CANCEL;
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intentNotification, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
final int NOTIFICATION_ID = 1;
notificationManager.notify(NOTIFICATION_ID, notification);
}
I’ve only set icon = 0 just to stop it from giving me errors. I know I need to use R.drawable in someway to get the actual icon ID. Just not sure why this isn’t working
Check your imports.
You want to import COM.YOURAPP.R, not android.R