此代码用于工作......
public void displayNotification(String msg) {
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.aow, msg, System.currentTimeMillis());
// The PendingIntent will launch activity if the user selects this
// notification
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this,
com.redcricket.whale_ship_essex_banner.whale_ship_essex_bannerActivity.class),
0);
notification.setLatestEventInfo(this, getResources().getString(R.string.app_name),
com.redcricket.whale_ship_essex_banner.whale_ship_essex_bannerActivity.track_titles[ currentTrack ], contentIntent);
manager.notify(0, notification);
}
...但现在我收到以下错误消息:
The constructor Notification(int, CharSequence, long) is deprecated
The method setLatestEventInfo(whale_ship_essex_bannerService, String, String, PendingIntent) is undefined for the type Notification
有人可以告诉我需要更改什么或者有关如何重写此代码的文档吗?
谢谢!
答案 0 :(得分:2)
您应该使用NotificationBuilder而不是构造函数。
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle("Some title")
.setSmallIcon(R.drawable.ic_launcher);
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
builder.setLargeIcon(bm);
Notification notification = builder.build();