2012-05-16 2 views
0
public class test extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.test); 

     String extra = "test"; 

     NotificationManager myNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 

     Intent intent = new Intent(this, another.class); 

     Notification notification = new Notification(R.drawable.ic_launcher, extra, 
       System.currentTimeMillis()); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 
       0, 
       intent, 
       PendingIntent.FLAG_UPDATE_CURRENT); 

     notification.setLatestEventInfo(getApplicationContext(), "title", "text", pendingIntent); 


     notification.defaults|= Notification.DEFAULT_SOUND; 
     notification.defaults|= Notification.DEFAULT_LIGHTS; 
     notification.defaults|= Notification.DEFAULT_VIBRATE; 
     notification.flags |= Notification.FLAG_INSISTENT; 
     notification.flags |= Notification.FLAG_AUTO_CANCEL; 

     myNotificationManager.notify(1, notification); 
    } 
} 

이 스 니펫 코드는 정상적으로 작동합니다. 실행하면 상태 표시 줄에서 알림을 확인할 때까지 알림 소리가 끊임없이 울립니다. 끊임없이 울리는 대신 한 번만 울리게하는 방법이 있습니까?알림 관리자와 함께 Android가 반복적으로 울림

답변

7

문서에서 플래그 Notification.FLAG_INSISTENT

을 제거 : "비트가 설정되면 알림이 취소되거나 알림 창이 열릴 때까지, 오디오가 반복 될 것이라는 플래그 필드에 비트 단위의 논리합합니다."

+0

감사합니다. 당신 말이 맞습니다 .... –

관련 문제