2016-10-20 1 views
1

알림이 발생하는 경우에만 오디오 모드를 일시적으로 변경하는 방법을 묻고 싶습니다.안드로이드에서 알림이 발생하는 경우에만 오디오 모드를 프로그래밍 방식으로 변경하는 방법은 무엇입니까?

예를 들어 현재 모드가 조용하고 소리가 나지 않고 진동이 없도록하고 싶습니다. 알림이 발생하면 음량이 최대가되고 진동이 발생합니다. 알림이 완료되면 소리와 진동없이 자동 모드로 다시 변경하려고합니다.

문제는 소리가 최대 볼륨과 진동으로 변할 수 있지만 알림이 완료된 후에도 오디오 설정이 진동으로 최대 사운드를 유지한다는 것입니다.

내 코드입니다 :

AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); 

audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 
          audioManager.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION), 
          AudioManager.FLAG_ALLOW_RINGER_MODES); 

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
notificationManager.notify(GCMHandler.MESSAGE_NOTIFICATION_ID, 
          NotificationBuilder.build(context, 
                "Mohon konfirmasi booking #" + bookings.last().getCode(), 
                "Booking #"+bookings.last().getCode()+" belum dikonfirmasi!", 
                NotificationBuilder.Type.PUSH_NOTIFICATION, 
                R.drawable.notif_icon, 0xFFC200)); 

내가 notificationManager.notify()audioManager.setRingerMode(RINGER_MODE_SILENT)를 넣어 경우, 알림이 가득한 자동 모드로

감사합니다,

답변

0

이 **이 코드의 뜻에 도움이 생각을 내장 모바일의 기본 벨소리로 설정 자동 모드 인 경우 다른 기본 알림 톤을 진동합니다

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this) 
      .setSmallIcon(R.drawable.piconebg) 
      .setContentTitle(title) 
      .setSubText(title3) 
      .setContentText(message) 
      .setAutoCancel(true) 
      .setTicker(title) 
      .setDefaults(Notification.DEFAULT_LIGHTS) 
     .setColor(color) 
      .setStyle(new  NotificationCompat.BigTextStyle().bigText(title)) 
      .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) 
      .setWhen(System.currentTimeMillis()) 
      .setLargeIcon(BitmapFactory.decodeResource(PushNotificationService.this.getResources(), R.drawable.push)) 
      .setSound(defaultSoundUri) 
      .setContentIntent(pendingIntent); 
    NotificationManager notificationManager = 
      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.notify(id /* ID of notification unique */,notificationBuilder.build()); 
+0

NotificationCompat.Builder는 아무 관계가 없습니다. 전에 setSound 및 setVibrate를 사용하여 시도해 보았습니다. 초기 모드가 조용한 경우 아무 일도 일어나지 않습니다. 내가 아는 한, setSound는 알림이 발생할 때 재생할 사운드의 종류에 관한 것입니다. 응답을위한 Thx –

관련 문제