我正在尝试为我的应用程序实现一个提醒功能,即API 23。
但是,提醒功能包含一个错误,即方法" setLatestEventInfo&#34>无法解决。
我做了一些研究,结果证明这种方法在API 23中已被弃用。我知道有类似的问题,但解决方案对我不起作用。
以下是相关代码:
public class ReminderService extends WakeReminderIntentService {
public ReminderService() {
super("ReminderService");
}
@Override
void doReminderWork(Intent intent) {
Log.d("ReminderService", "Doing work.");
Long rowId = intent.getExtras().getLong(RemindersDbAdapter.KEY_ROWID);
NotificationManager mgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(this, ReminderEditActivity.class);
notificationIntent.putExtra(RemindersDbAdapter.KEY_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;
// An issue could occur if user ever enters over 2,147,483,647 tasks. (Max int value).
// I highly doubt this will ever happen. But is good to note.
int id = (int)((long)rowId);
mgr.notify(id, note);
}
}
如何在不降低API级别的情况下解决此问题?
答案 0 :(得分:0)
使用NotificationCompat.Builder制作通知,如documentation。
您可以查看方法setTicker
,setSmallIcon
,setContentTitle
,setContentText
,setContentIntent
,setAutoCancel
,setDefaults
重现你的行为。