Notifications.Builder在API 10 [英] Notifications.Builder in API 10

查看:169
本文介绍了Notifications.Builder在API 10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这给了错误:

This gives error:

调用需要API级别11(目前最小为10):android.app.Notification $生成器#setContentIntent

我下载的 android.support.v4.jar 添加到libs文件夹在同一目录中的 SRC 资源等。

I downloaded android.support.v4.jar added it to libs folder in the same directory as src and res etc.

右键点击这个罐子从项目资源管理器,并添加到构建路径。

right click on this jar from the project explorer and add to build path.

我的应用程序有一个分钟API = 10 目标API = 15

my application has a min api = 10 and target api = 15

感谢您

推荐答案

有关通知的支持类似乎有不同的名称,<一个href="http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html"><$c$c>NotificationCompat.为了您的API 10 code,你需要使用:

The support class for Notification seems to have a different name, NotificationCompat. For your API 10 code you'll need to use:

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

和改变你的import语句:

And change your import statement to:

import android.support.v4.app.NotificationCompat.Builder;

这篇关于Notifications.Builder在API 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆