当前位置: 首页 > 知识库问答 >
问题:

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

祁乐邦
2023-03-14

我无法修复Eclipse中的这个错误。是引进项目。除了这个错误之外,其他一切都很好:

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;
    }

}

共有1个答案

卓嘉良
2023-03-14

方法setLatestEventInfo(Context,String,String,PendingIntent)在以前的Android版本中是不推荐的,在API V23中已经删除了。如果你的目标是那个版本的Android系统,你将无法使用该方法

编辑:为了更新通知信息,您可以使用NotificationManager.Notify(),它是API23的一部分。

 类似资料: