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年前的新事物。 –