未定义类型通知的方法 setPriority (int) [英] The method setPriority (int) is undefined for the type Notification

查看:37
本文介绍了未定义类型通知的方法 setPriority (int)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从 Jelly Bean 以来,可以设置通知的优先级.这样你甚至可以设置 PRIORITY_MIN 来隐藏状态栏上的通知图标.我读过它,它很简单,你只需要使用这个:

Since Jelly Bean it is possible to set a priority to notifications. This way you can even set PRIORITY_MIN which will hide the notification icon on status bar. I read about it and it is very simple, you just have to use this:

MyNotification.setPriority(Notification.PRIORITY_MIN);

我的问题是我收到编译错误:未定义通知类型的 setPriority (int) 方法"

My problem es that I get the compile error: "The method setPriority (int) is undefined for the type Notification"

我的应用程序必须在不同版本的 Android 中运行,所以,我知道该功能在 JellyBean 下不可用,所以有没有办法包含编译器标签或类似的东西来添加该功能,具体取决于 Android 版本.我希望你明白我的意思.

My application has to run in different versions of Android, so, I understand that function is not available under JellyBean, so is there a way to include compiler tags or something similar to add that functionality depending on the Android release. I hope you understand what I mean.

推荐答案

Android 会自动处理这个问题.无需对特定版本号进行额外标记.当涉及到您的编译错误时,我很幸运,我的代码类似于下面的代码.您要确保使用 NotificationCompat 并确保导入 android.support.v4.app.NotificationCompat;.

Android will handle this automagically. No need for additional markup for specific version numbers. When it comes to your compile error, I've had luck with something like my code below. You want to make sure to use NotificationCompat and make sure you import android.support.v4.app.NotificationCompat; as well.

int pri = 0;
NotificationCompat.Builder MyNotification = new NotificationCompat.Builder(ctx);
MyNotification.setPriority(pri);

这篇关于未定义类型通知的方法 setPriority (int)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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