同时采用Notification.Builder收到错误 [英] getting errors while using Notification.Builder
本文介绍了同时采用Notification.Builder收到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到这些线路同时处理不同的API级别的通知错误。我这是怎么做到到目前为止:
...
INT currentapiVersion = android.os.Build.VERSION.SDK_INT;
通知通知;如果(currentapiVersion< android.os.Build.VERSION_ codeS.HONEYCOMB){ 通知=新的通知(图标,文字,时间);
的PendingIntent contentIntent = PendingIntent.getActivity(在此,0,新意图(此,TaskDetails.class),0);
notification.setLatestEventInfo(这一点,标题,正文,contentIntent);
notification.flags | = Notification.FLAG_AUTO_CANCEL;
mNM.notify(通知,通知);
}
其他
{
通知=新Notification.Builder(本)//错误
.setContentTitle(职称)//在
.setContentText(tmp_task_brief)//这些
.setSmallIcon(图标)//线
.setLargeIcon(NULL)//告诉这个方法调用需要API级别11
。建立(); // 或更高 的PendingIntent contentIntent = PendingIntent.getActivity(在此,0,新意图(此,TaskDetails.class),0);
notification.setLatestEventInfo(这一点,标题,正文,contentIntent);
notification.flags | = Notification.FLAG_AUTO_CANCEL;
mNM.notify(通知,通知);
}
...
我不明白如何删除这些错误。请帮我。
编辑:我并应用于如下修改,但NotificationCompact.Builer也得到了德precated方法的GetNotification()
返回通知对象
如果(currentapiVersion< android.os.Build.VERSION_ codeS.HONEYCOMB)
{
通知=新的通知(图标,文字,时间);
notification.setLatestEventInfo(这一点,标题,正文,contentIntent);
notification.flags | = Notification.FLAG_AUTO_CANCEL;
mNM.notify(通知,通知);
}
其他
{
NotificationCompat.Builder建设者=新NotificationCompat.Builder(本);
builder.setContentIntent(contentIntent)
.setSmallIcon(图标)
.setTicker(文本)
.setWhen(System.currentTimeMillis的())
.setAutoCancel(真)
.setContentTitle(职称)
.setContentText(文本); 通知= builder.getNotification();
mNM.notify(通知,通知);
}
解决方案
使用的从支持liberary(V4 liberary)NotificationCompact.Bulide R,它将从1.6支持
我认为这将解决您的问题。
I am getting errors with these lines while handling notifications for different API levels. This is how i did so far:
...
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
Notification notification;
if (currentapiVersion < android.os.Build.VERSION_CODES.HONEYCOMB){
notification = new Notification(icon, text, time);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, TaskDetails.class), 0);
notification.setLatestEventInfo(this, title, text, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNM.notify(NOTIFICATION, notification);
}
else
{
notification = new Notification.Builder(this) // error
.setContentTitle(title) // in
.setContentText(tmp_task_brief) // these
.setSmallIcon(icon) // lines
.setLargeIcon(null) // telling "this method call requires API level 11
.build(); // or higher"
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, TaskDetails.class), 0);
notification.setLatestEventInfo(this, title, text, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNM.notify(NOTIFICATION, notification);
}
...
I don't understand how to remove these errors. Please help me.
Edit: I did applied edit as below but NotificationCompact.Builer too got deprecated method getNotification()
that returns Notification object.
if (currentapiVersion < android.os.Build.VERSION_CODES.HONEYCOMB)
{
notification = new Notification(icon, text, time);
notification.setLatestEventInfo(this, title, text, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNM.notify(NOTIFICATION, notification);
}
else
{
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentIntent(contentIntent)
.setSmallIcon(icon)
.setTicker(text)
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentTitle(title)
.setContentText(text);
notification = builder.getNotification();
mNM.notify(NOTIFICATION, notification);
}
解决方案
Use NotificationCompact.Bulider from support liberary (V4 liberary) that supports from 1.6
i think that will solves your problem.
这篇关于同时采用Notification.Builder收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文