0

我试图显示单挑通知,但android工作室根本无法识别符号PRIORITY_HIGH无法解析符号`PRIORITY_HIGH`

下面是代码:

Intent intent1 = new Intent(context1,MainActivity.class); 
     PendingIntent pendingNotificationIntent = PendingIntent.getActivity(context1,0, intent1,PendingIntent.FLAG_UPDATE_CURRENT); 
     NotificationCompat.Builder builder = new NotificationCompat.Builder(context1); 
     builder.setSmallIcon(R.mipmap.ic_launcher) 
       .setLargeIcon(BitmapFactory.decodeResource(context1.getResources(), R.mipmap.ic_launcher)) 
       .setContentTitle("MOODS") 
       .setContentIntent(pendingNotificationIntent) 
       .setContentText("Quote:\t"+quote+"\nAuthor:\t" +author) 
       .setDefaults(Notification.DEFAULT_ALL) 
       .setPriority(Notification.PRIORITY_HIGH); 
+0

欢迎的话,你需要更具体和你所面对的错误。发布构建日志会更好(运行构建并在此处粘贴日志错误)。 –

+1

您正在使用'NotificationCompat'。同样使用'NotificationCompat.PRIORITY_HIGH'。 – njzk2

+0

哦,它的工作。 TNX! – zobrist23

回答

0

DEFAULT_ALL因为API版本1已经存在,而

PRIORITY_HIGH与API版本中引入了16

这是我的假设,你的API级别设置为这两者之间的东西。

鉴于您正在使用compat库,您还应该使用此处的标志。

你有两个解决方案,撞你的API版本16+,或使用

NotificationCompat.PRIORITY_HIGH

+0

是的,它被设置为10.但是它呢?我该怎么办? – zobrist23

+0

直到16年才推出...所以你如何期望在10年内使用它?找到另一种方式,或将您的版本升级到16+。 –

+1

@ zobrist23您正在*编译*针对API级别10?我的天啊。怎么样?那是5年前的新事物。 –