1

错误:Notification.Builder 类型的方法 build() 未定义

我添加了 android-support-v4.jar 仍然出现错误?

Notification notification = new Notification.Builder(context)
        .setContentText(message)
        .setContentTitle(context.getString(R.string.app_name))
        .setSmallIcon(icon)
        .setWhen(when)
        .setContentIntent(intent).build();
4

2 回答 2

6

我的猜测是你android-support-v4.jar太老了。build()大约在一年前添加,但在 Android 支持包首次发布之后。

确保您在 SDK 管理器中下载了最新的 Android 支持包,然后将最新版本android-support-v4.jarextras/SDK 目录复制到您的项目中。

于 2013-10-28T12:43:50.227 回答
4

尝试这个 :

NotificationCompat.Builder builder = new NotificationCompat.Builder(
                    context);
        Notification notification = builder.setContentIntent(contentIntent)
                    .setSmallIcon(icon).setTicker(appname).setWhen(when)
                    .setAutoCancel(true).setContentTitle(appname)
                    .setContentText(message).build();

            notificationManager.notify(0, notification);

希望这可以帮助。

于 2013-10-28T12:44:39.373 回答