Android – Method setpriority (int) does not define notification type

Starting with Jerry bean, you can set priority for notifications. In this way, you can even set priority_ Min, this will hide the notification icon on the status bar. I read it and it's very simple. You just need to use it:

MyNotification.setPriority(Notification.PRIORITY_MIN);

My problem is that I got a compilation error: "method setpriority (int) undefined type notification"

My application must run in different versions of Android, so I know there is no such function under jellybean, so is there any way to include compiler tags or similar things and add this function according to the Android version. I hope you understand what I mean

resolvent:

Android will automatically handle this problem. There is no need to add additional tags for a specific version number. When you encounter compilation errors, I have been lucky to encounter code similar to me. You want to ensure that notificationcompat is used and that android.support.v4.app.notificationcompat is imported; Same

This code should be valid:

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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>