未知方法setLatestEventInfo

时间:2015-11-07 02:05:54

标签: java android

我正在尝试创建自动更新应用并从此处获取源代码:https://code.google.com/p/auto-update-apk-client/downloads/detail?name=auto-update-apk-client_2012-10-04.tgz&can=2&q=

但我收到错误“未知方法setLatestEventInfo”

感谢您的帮助。

protected void raise_notification() {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nm = (NotificationManager) context.getSystemService(ns);

    String update_file = preferences.getString(UPDATE_FILE, "");
    if( update_file.length() > 0 ) {
        setChanged();
        notifyObservers(AUTOUPDATE_HAVE_UPDATE);

        // raise notification
        Notification notification = new Notification(
                appIcon, appName + " update", System.currentTimeMillis());
        notification.flags |= NOTIFICATION_FLAGS;

        CharSequence contentTitle = appName + " update available";
        CharSequence contentText = "Select to install";
        Intent notificationIntent = new Intent(Intent.ACTION_VIEW );
        notificationIntent.setDataAndType(
                Uri.parse("file://" + context.getFilesDir().getAbsolutePath() + "/" + update_file),
                ANDROID_PACKAGE);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        nm.notify( NOTIFICATION_ID, notification);
    } else {
        nm.cancel( NOTIFICATION_ID );
    }
}

1 个答案:

答案 0 :(得分:0)

此方法在API级别11中已弃用。您应该使用NotificationBuilder代替。 请查看Building a Notification lessonthis答案。