2016-10-20 4 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 –

関連する問題