2015-11-27 39 views
0

從此blog我瞭解到,對於所有媒體應用程序,我都應請求AudioFocus,並且只有在授予AudioFocus時纔開始播放。我需要爲報警應用程序設置哪種AudioFocus

am.requestAudioFocus(audioFocusChangeListener,AudioManager.STREAM_ALARM,AudioManager.AUDIOFOCUS_GAIN); 

我在做報警應用程序。
作爲一個鬧鐘,它應該一直響鈴直到被解僱 - 除了在電話通話期間(這是合乎邏輯的)。

如果一個呼叫振鈴或空閒通過使用TelephonyManager

TelephonyManager telephonyManager = 
     (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); 
    telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); 

    switch (telephonyManager.getCallState()) { 
     case TelephonyManager.CALL_STATE_IDLE: 
     outsidePause = false; 
     break; 
     default: 
     outsidePause = true; 
     break; 
    } 
PhoneStateListener phoneStateListener = new PhoneStateListener() { 
    @Override public void onCallStateChanged(int state, String incomingNumber) { 
     switch (state) { 

     case TelephonyManager.CALL_STATE_IDLE: 
      outsidePause = false; 
      Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, 
       Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); 
      android.provider.Settings.System.putInt(getContentResolver(), 
       android.provider.Settings.System.SCREEN_BRIGHTNESS, (0)); 
      am.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0); 
      setInnerData(); 
      startAlarm(); 
      break; 
     default: 
      outsidePause = true; 
      vibrator.cancel(); 
      pauseAlarm(); 
      break; 
     } 
     super.onCallStateChanged(state, incomingNumber); 
    } 
    }; 

以在帳戶中的TelephonyManager我可以跟蹤,是有用和所必要的使用AudioFocus(如果它是,該模式是preferrable) ?

另一個應用程序可以從我的,使沉默警報?

回答

0

似乎,如果確定使用音頻焦點。 Othet應用程序不會採取它,直到我放棄它。

相關問題