gpt4 book ai didi

java - 如何修复方法 setLatestEventInfo(Context, String, String, PendingIntent) 未定义类型通知

转载 作者:行者123 更新时间:2023-12-01 10:51:26 31 4
gpt4 key购买 nike

我无法修复在 Eclipse 中遇到的此错误。这是一个引进的项目。除了这个错误之外,其他一切都正常:

The method setLatestEventInfo(Context, String, String, PendingIntent) is undefined for the type Notification MyNotificationBuilderToGingerBread.java /CANAPP/src/com/ftech/canapp/notification line 14 Java Problem

这是我正在处理的代码

package com.ftech.canapp.notification;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;

public class MyNotificationBuilderToGingerBread {

Notification notification = null;

@SuppressWarnings("deprecation")
public MyNotificationBuilderToGingerBread(Context myContext, int icon, String ticker, String title, String info, Long timeStamp, PendingIntent pendingIntent) {
notification = new Notification(icon, ticker, timeStamp);
notification.setLatestEventInfo(myContext, title, info, pendingIntent);
}

@SuppressWarnings("deprecation")
public MyNotificationBuilderToGingerBread(Context myContext, int icon, String ticker, String title, String info, Long timeStamp, PendingIntent pendingIntent, int flags) {
notification = new Notification(icon, ticker, timeStamp);
notification.setLatestEventInfo(myContext, title, info, pendingIntent);
}

public Notification get() {
return notification;
}

}

最佳答案

我已在所有版本中使用此包装器:

public static Notification notification(Context ctx, String title, int icon,
long when, PendingIntent pIntent, String contentTitle,
String contentText,int flags, int defaults){
NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx);
Notification notification = builder.setContentIntent(pIntent)
.setSmallIcon(icon).setTicker(title).setWhen(when).setContentTitle(contentTitle)
.setContentText(contentText).setDefaults(defaults).build();
notification.flags = flags;
return notification;
}

关于java - 如何修复方法 setLatestEventInfo(Context, String, String, PendingIntent) 未定义类型通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33857636/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com