简体   繁体   English

调用需要API级别16(当前最小值为14):android.app.Notification.Builder #build

[英]Call requires API level 16 (current min is 14): android.app.Notification.Builder#build

在此输入图像描述 The documentation says Notification.Builder is Added in API level 11. Why I get this lint error? 文档说在API级别11中添加了Notification.Builder。为什么我会收到此lint错误?

Call requires API level 16 (current min is 14): android.app.Notification.Builder#build 调用需要API级别16(当前最小值为14):android.app.Notification.Builder #build

notification = new Notification.Builder(ctx)
                .setContentTitle("Title").setContentText("Text")
                .setSmallIcon(R.drawable.ic_launcher).build();

Manifest: 表现:

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="17" />

Am I missing something? 我错过了什么吗?

Correct me if I am wrong but the API is added in level 11, right? 如果我错了,请纠正我但是在11级添加了API,对吗? Added in API level 11 在API级别11中添加

NotificationBuilder.build() requires API Level 16 or higher. NotificationBuilder.build()需要API级别16或更高级别。 Anything between API Level 11 & 15 you should use NotificationBuilder.getNotification() . API级别11和15之间的任何内容都应该使用NotificationBuilder.getNotification() So use 所以使用

notification = new Notification.Builder(ctx)
                .setContentTitle("Title").setContentText("Text")
                .setSmallIcon(R.drawable.ic_launcher).getNotification();

The tip about the API level needing to be 16 is right. 关于需要16的API级别的提示是正确的。 This worked for me 这对我有用

if (Build.VERSION.SDK_INT < 16) {
    nm.notify(MY_NOTIFICATION_ID, notificationBuilder.getNotification());
} else {
    nm.notify(MY_NOTIFICATION_ID, notificationBuilder.build());
}

I was having the problem where the notification worked fine on newer devices but not on Android 4.0.4 (API level 15). 我遇到的问题是,通知在较新的设备上正常工作,但在Android 4.0.4(API级别15)上没有。 I do get a deprecation warning form eclipse. 我确实得到了eclipse的弃用警告形式。 @SuppressWarnings("deprecation") doesn't entirely hide it but I think that is probably helpful. @SuppressWarnings(“弃用”)并不完全隐藏它,但我认为这可能有帮助。

Android Lint is a new tool introduced in ADT 16 (and Tools 16) which scans Android project sources for potential bugs. Android Lint是ADT 16(和工具16)中引入的一种新工具,可以扫描Android项目源中的潜在错误。 It is available both as a command line tool, as well as integrated with Eclipse 它既可以作为命令行工具使用,也可以与Eclipse集成

http://tools.android.com/tips/lint http://tools.android.com/tips/lint

For list of lint checks 对于棉绒检查列表

http://tools.android.com/tips/lint-checks http://tools.android.com/tips/lint-checks

For supressing lint warning 用于抑制棉绒警告

http://tools.android.com/tips/lint/suppressing-lint-warnings http://tools.android.com/tips/lint/suppressing-lint-warnings

http://developer.android.com/reference/android/app/Notification.Builder.html http://developer.android.com/reference/android/app/Notification.Builder.html

If your app supports versions of Android as old as API level 4, you can instead use NotificationCompat.Builder, available in the Android Support library. 如果您的应用支持的API版本与API级别4一样旧,则可以使用Android支持库中提供的NotificationCompat.Builder。

For support library 对于支持库

http://developer.android.com/tools/extras/support-library.html http://developer.android.com/tools/extras/support-library.html

You can use from this : 你可以使用这个:

if (Build.VERSION.SDK_INT < 16) {
                Notification n  = new Notification.Builder(this)
                        .setContentTitle("New mail from " + "test@gmail.com")
                        .setContentText("Subject")
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setContentIntent(pIntent)
                        .setAutoCancel(true).getNotification();
                NotificationManager notificationManager =
                        (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                notificationManager.notify(0, n);
            } else {
                Notification n  = new Notification.Builder(this)
                        .setContentTitle("New mail from " + "test@gmail.com")
                        .setContentText("Subject")
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setContentIntent(pIntent)
                        .setAutoCancel(true).build();
                NotificationManager notificationManager =
                        (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                notificationManager.notify(0, n);
            }

I have same problem in android studio. 我在android studio中遇到同样的问题。 I did minor change in build.gradle(module:app) file and Problem has been solved. 我在build.gradle(module:app)文件中做了一些小改动,问题已经解决了。 在此输入图像描述

After sync project. 同步项目后。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调用要求API级别16(当前最小值为14),并带有EndAction - Call requires API level 16 (current min is 14) withEndAction 呼叫需要API级别16(当前最小值为14) - Call requires API level 16 (current min is 14) 调用需要API级别11(当前最小值为8):new android.app.AlertDialog.Builder - Call requires API level 11 (current min is 8): new android.app.AlertDialog.Builder 呼叫需要API级别14(当前最小值为11) - Call requires API level 14 (current min is 11) 调用需要API级别14(当前最小值为10): - Call requires API level 14 (current min is 10): Sherlock:android:textAllCaps需要API级别14(当前最小值为8) - Sherlock : android:textAllCaps requires API level 14 (current min is 8) 通话需要 API 级别 21(当前最低为 14):android.speech.tts.TextToSpeech#speak - Call requires API level 21 (current min is 14): android.speech.tts.TextToSpeech#speak 调用需要API级别14(当前最小值为8):android.view.ViewGroup#canScrollHorizo​​ntally - Call requires API level 14 (current min is 8): android.view.ViewGroup#canScrollHorizontally Android皮棉:不显示消息“呼叫要求API级别17(当前最小值为14)” - Android lint: does not show message “Call requires API level 17 (current min is 14)” 调用需要API级别16(当前最小值为10):android.widget.ImageView#getMaxWidth - Call requires API level 16 (current min is 10): android.widget.ImageView#getMaxWidth
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM