API 10中的Notifications.Builder

Arc*_*pgc 3 notifications android

Notification.Builder builder = new Notification.Builder(this);

builder.setContentIntent(contentIntent)
    .setSmallIcon(R.drawable.ic_launcher)
    .setTicker(notificationMessage)
    .setWhen(System.currentTimeMillis())
    .setAutoCancel(true)
    .setContentTitle(newNotificationsCount + " New Notifications")
    .setContentText(notificationMessage);

Notification notification = builder.getNotification();
nm.notify(R.string.app_name, notification);
Run Code Online (Sandbox Code Playgroud)

这给出了错误:

调用需要API级别11(当前最小值为10):android.app.Notification $ Builder #setContentIntent

我下载了android.support.v4.jar将它添加到与srcres等目录相同的libs文件夹中.

右键单击项目资源管理器中的jar并添加到构建路径.

我的应用程序有一个最小api = 10目标api = 15

谢谢

Sam*_*Sam 19

Notification的支持类似乎有不同的名称NotificationCompat.对于您的API 10代码,您需要使用:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
Run Code Online (Sandbox Code Playgroud)

并将您的import语句更改为:

import android.support.v4.app.NotificationCompat.Builder;
Run Code Online (Sandbox Code Playgroud)