private bool RequestAudioFocus() { audioManager = (AudioManager)GetSystemService(Context.AudioService); AudioFocusRequest result = audioManager.RequestAudioFocus(this, Stream.Music, AudioFocus.Gain); if (result == AudioFocusRequest.Granted) { //Focus gained return(true); } //Could not gain focus return(false); }
private void Init() { if (initialized) { Realese(); } tokenParser = new DTMFTokenParser(); ISharedPreferences shared_prefs = Global.GetSharedPreferences(this); shared_prefs.RegisterOnSharedPreferenceChangeListener(this); prefs_model = new PreferencesModel(shared_prefs); var audio_mngr = (AudioManager)GetSystemService(Context.AudioService); AudioFocusRequest result = audio_mngr.RequestAudioFocus(this, Stream.Music, AudioFocus.Gain); if (prefs_model.Notificando) { Notificando = true; } //modoComplemento = prefs_model.Modo_Complemento; TelephonyManager tmgr = (TelephonyManager)this.GetSystemService(Service.TelephonyService); if (phone_state_listener == null) { phone_state_listener = new MyPhoneStateListener(this); } tmgr.Listen(phone_state_listener, PhoneStateListenerFlags.CallState); initialized = true; Schudled_CallBack = prefs_model.Schudled_Call; if ((prefs_model.Teclado_Enabled || prefs_model.Ready) && !Detecting) { new System.Threading.Timer((o) => { StartDetect(); }, null, 2000, -1); } }