0

我想为我的应用创建通知

它告诉我构造函数 Notification(,,) 已弃用

并且方法 .setLatestEventInfo() 也已弃用

我应该怎么做?

这是类代码:

public class ReminderService extends WakeReminderIntentService {

public ReminderService() {
    super ("ReminderService");
}

@Override
void doReminderWork(Intent intent) {
    long rowid = intent.getExtras().getLong(ReminderProvider.COLUMN_ROWID);

    NotificationManager mgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    Intent notificationIntent = new Intent (this, ReminderEditActivity.class);
    notificationIntent.putExtra(ReminderProvider.COLUMN_ROWID, rowid);
    PendingIntent Pi = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT);
    Notification note=new Notification(android.R.drawable.stat_sys_warning, getString(R.string.notify_new_task_message), System.currentTimeMillis());
    note.setLatestEventInfo(this, getString(R.string.notify_new_task_title), getString(R.string.notify_new_task_message), Pi);
    note.defaults |= Notification.DEFAULT_SOUND;
    note.flags |= Notification.FLAG_AUTO_CANCEL;
    int id = (int) ((long) rowid);
    mgr.notify(id, note);

}

}

4

2 回答 2

1

为此使用 NotificationCompat.Builder。http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html

于 2013-04-13T16:57:38.783 回答
1
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setContentIntent(pendingIntent);

尝试类似的东西

于 2017-08-20T19:05:33.223 回答