【发布时间】:2012-06-26 04:26:24
【问题描述】:
我目前正在开发一个 android 项目,我正在尝试从标准 java 类(不是活动类)创建通知。
我在名为 icon.png 的可绘制文件夹中添加了一个图标,但是当我尝试使用 R.drawable.icon 将图标设置为 int 时,图标永远不会只显示默认的内置 android 图标。
我不明白为什么它没有显示我自己的图标。
感谢您提供的任何帮助。
更新 如下要求是设置通知的代码
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);
}
我只设置了icon = 0 只是为了阻止它给我错误。我知道我需要以某种方式使用 R.drawable 来获取实际的图标 ID。只是不知道为什么这不起作用
【问题讨论】:
-
您能否向我们展示您设置通知的代码?
标签: android notifications icons