Reputation: 36205
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
Upvotes: 0
Views: 514
Reputation: 1624
I am not sure why I can't add comment to this question. Anyway have you tired to click on project menu and then click Clean..? then open R.java file and see if your icon is listed there? Try this :
int icon = R.drawable.icon;
instead of
int icon =0;
Upvotes: 0
Reputation: 1621
Check your imports.
You want to import COM.YOURAPP.R, not android.R
Upvotes: 2