setLatestEventInfo方法无法解析 [英] setLatestEventInfo method cannot be resolved
问题描述
我正在尝试为我的应用程序实现提醒功能,即API 23.
I am trying to implement a reminder feature for my application which is API 23.
但是,提醒功能包含一个错误,无法解决方法"setLatestEventInfo".
However, the reminder feature contains an error whereby the method "setLatestEventInfo" cannot be resolved.
我进行了一些研究,结果发现该方法已在API 23中弃用.我知道那里也有类似的问题,但是解决方案对我不起作用.
I have done some researching and it turns out that this method is deprecated in API 23. I know that there are similar questions out there, but the solutions did not work for me.
以下是相关代码:
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级别的情况下解决此问题?
How can I solve this without downgrading my API level?
推荐答案
使用 NotificationCompat.Builder 来构建您的通知,如
Use NotificationCompat.Builder to build your notifications as in the documentation.
您可以检查方法setTicker
,setSmallIcon
,setContentTitle
,setContentText
,setContentIntent
,setAutoCancel
,setDefaults
以重现您的行为.
You can check the methods setTicker
, setSmallIcon
, setContentTitle
, setContentText
, setContentIntent
, setAutoCancel
, setDefaults
to reproduce your behaviour.
这篇关于setLatestEventInfo方法无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!