2012-03-14 5 views
2

Android 4.0에서 Galaxy Nexus를 사용 중이며 설정에서 진동 모드로 설정합니다. NotificationManager.notify를 사용하여 알림을 보냅니다. 알림을 설정하지 않습니다. 진동, 진동을 비활성화하려면 myNotification.defaults & = ~ Notification.DEFAULT_VIBRATE를 사용합니다. 그러나 NotifcationManager.notify를 호출 한 후에도 여전히 진동합니다. 알림 모드를 진동 모드로 해제하는 방법을 알려주시겠습니까?알림의 기본 진동을 끄는 방법

notification.defaults = Notification.DEFAULT_LIGHTS; 
//or 
notification.defaults = Notification.DEFAULT_SOUND; 

답변

3

다음 코드를 사용합니다. 그런 다음 알림을 수신하는 곳에이 코드를 삽입하십시오.

SharedPreferences preferences = context.getSharedPreferences("VIBRATE", 
      0); 
boolean vibrate = preferences.getBoolean("vibrate", true); 
if (vibrate) { 
     notification.defaults |= Notification.DEFAULT_VIBRATE; 
    } 
1

동적 알림 설정을 관리하려면 :

notification.defaults = Notification.DEFAULT_LIGHTS; 

if(/*sound enabled*/) 
    notification.defaults |= Notification.DEFAULT_SOUND; 

if(/*vibration enabled*/) 
    notification.defaults |= Notification.DEFAULT_VIBRATE; 
0

먼저 저장 공유 환경 설정에서 설정 버튼을 당신의 진동의 값

1

알림이 올 때 진동을 사용하지 않으려면이 코드를 사용하십시오.

notification.vibrate = new long[] { -1 }; 

그리고 완벽하게 작동합니다.

관련 문제