2017-04-09 5 views
0

특정 비컨이 감지 될 때 잠긴 화면에 알림이 표시되도록하는 알림 메서드를 작성하려고합니다. 기호 메서드를 찾을 수 없습니다.

public void showNotification(Beacon beacon) { 

    Resources r = getResources(); 
    int random = (int)System.currentTimeMillis(); 
    Notification notification = new NotificationCompat.Builder(this) 
      .setSmallIcon(android.R.drawable.ic_popup_reminder) 
      .setContentTitle("Beacons Found") 
      .setContentText(beacon.getID().toString()) 
      .setVisibility(0) // allow notification to appear on locked screen 
      .setAutoCancel(true) 
      .build(); 

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    notificationManager.notify(random, notification); 

} 

내가 위의 코드를 가지고,하지만 난 그것을 실행할 때 말한다 "기호 방법 setVisibility (int)를 찾을 수 없습니다"나의 이해는 내가 다음 코드 (0) .setVisibility을 포함 할 필요가 있다는 것입니다. 나는 몇 가지 조사를 온라인했을 그리고 내가 이것들을 가져와야 보인다

import android.support.v4.app.NotificationCompat; 
import android.app.Notification; 
import android.app.NotificationManager; 

내가이 수입을 포함하더라도, 난 여전히 같은 오류 메시지가 표시됩니다. 누구든지 도와 줄 수 있습니까? 감사!!

답변

0

Api 21에 setVisibility()가 추가되었습니다. 설명서에 따르면이 도구를 사용해 볼 수 있습니다. 그는 NotificationCompat을 사용하고 따라

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { 

    Notification notification = new NotificationCompat.Builder(this) 
     .setSmallIcon(android.R.drawable.ic_popup_reminder) 
     .setContentTitle("Beacons Found") 
     .setContentText(beacon.getID().toString()) 
     .setVisibility(0) // allow notification to appear on locked screen 
     .setAutoCancel(true) 
     .build(); 

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
notificationManager.notify(random, notification); 

} 
+0

, 그는 그래서 당신은 LOLLIPOP_MR1에 버전 코드를 변경해야 API (22)를 대상으로한다 : –

+0

감사합니다 모두, 나는 위의 코드를 추가하려고하지만 "기호 변수 롤리팝를 찾을 수 없습니다"라고 .. 이 문제를 해결하려면 무엇을해야합니까? –

+0

오류가 발생해서는 안됩니다. 프로젝트를 동기화하고 정리 한 다음 프로젝트를 다시 작성하십시오. 오류가 발생하면 어떤 gradle 오류가 발생합니까? – Queendevelopers

관련 문제