您好我是Android新手,我正在尝试创建Notification.Builder通知,但我失败了。启动通知时出现错误
public class CardImagePanel extends JPanel {
BufferedImage cardImage;
public CardImagePanel() {
this.setBorder(BorderFactory.createLineBorder(Color.black));
try {
cardImage = ImageIO.read(new File("c:\\dev\\cards\\2_of_clubs.png"));
} catch (IOException ex) {
System.out.println("Exception trying to load image file.");
}
}
@Override
public Dimension getPreferredSize() {
return cardImage != null ? new Dimension(cardImage.getWidth(), cardImage.getHeight()) : super.getPreferredSize();
}
@Override
public Dimension getMinimumSize() {
return getPreferredSize();
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(cardImage, 0, 0, this);
}
}
我已下载API'S 16 17 18 19 23, 这就是所有代码:
nm.notify(IDNOTIFICACIONUNO,notif); // Error in notif
我也是图书馆。谢谢你的帮助
答案 0 :(得分:0)
在notif.setSmallIcon(R.drawable.tree)之后有一个`characheter; 删除该charachter并运行代码。
答案 1 :(得分:0)
final NotificationManager nm =(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
//Connect to the button
Button iconBtn = (Button) findViewById(R.id.btn_icon);
//Set the button on click listener
iconBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(MainActivity.this, 0, notificationIntent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this);
Notification notification = builder.setContentIntent(contentIntent).setTicker("This is a notification marquee")
.setSmallIcon(R.drawable.ic_launcher).setWhen(System.currentTimeMillis())
.setAutoCancel(true).setContentTitle("Message Title")
.setContentText("Message Content").build();
//Show the notification
nm.notify(1, notification);
}
});