Programmatically switch off silent
Is it possible to switch the call ringer off silent dueing an incoming call?
I am able to change the phone to normal mode and set the volume of the ringer, but because the phone was in silent previously, it doesn't just start ringing after I change the settings.
What I am doing is, when the phone is in silent and I receive an incoming call, based on certain conditions I want the phone to actually ring.
As mentioned, I have changed the settings ok, so if I receive a subsequent call the ringer works, but the initial call (which triggered the change of settings) still continues to ring in silent mode... Is there a way to (after I set the ringer modes) to force the phone to "ring" with the new settings again?
Update:
I have set the ringer off silent and set to ring at max volume using the following:
AudioManager mAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
int origionalVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_RING);
int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
mAudioManager.setStreamVolume(AudioManager.STREAM_RING, maxVolume, AudioManager.FLAG_SHOW_UI + AudioManager.FLAG_PLAY_SOUND);
I can see in the logs that when the ringer is actually playing, it logs out:
06-13 19:22:33.984: DEBUG/CallNotifier(126): RINGING... (new)
06-13 19:22:33.984: DEBUG/CallNotifier(126): onNewRingingConnection(): incoming: true state: INCOMING post dial state: NOT_STARTED
06-13 19:22:34.094: INFO/ActivityManager(59): Start proc android.process.acore for content provider com.android.providers.contacts/.ContactsProvider2: pid=294 uid=10000 gids={3003, 1015}
06-13 19:22:34.444: INFO/ActivityThread(294): Publishing provider com.android.social: com.android.providers.contacts.SocialProvider
06-13 19:22:34.494: INFO/ActivityThread(294): Publishing provider applications: com.android.providers.ap开发者_C百科plications.ApplicationsProvider
06-13 19:22:34.594: WARN/CallNotifier(126): CallerInfo query took too long; manually starting ringer
06-13 19:22:34.594: WARN/CallNotifier(126): CallerInfo query took too long; falling back to default ringtone
06-13 19:22:34.594: DEBUG/Ringer(126): ring()...
06-13 19:22:34.664: INFO/ActivityManager(59): Start proc com.android.settings for broadcast com.android.settings/.widget.SettingsAppWidgetProvider: pid=301 uid=1000 gids={3002, 3001, 3003}
06-13 19:22:34.684: DEBUG/Ringer(126): mRingHandler: PLAY_RING_ONCE...
06-13 19:22:34.684: DEBUG/Ringer(126): creating ringtone: content://settings/system/ringtone
06-13 19:22:34.734: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN flg=0x10840000 cmp=com.android.phone/.InCallScreen }
06-13 19:22:35.374: DEBUG/InCallScreen(126): onCreate()... this = com.android.phone.InCallScreen@44f29ad0
06-13 19:22:35.504: INFO/ActivityThread(294): Publishing provider contacts;com.android.contacts: com.android.providers.contacts.ContactsProvider2
06-13 19:22:36.184: DEBUG/AudioHardwareInterface(34): setMode(RINGTONE)
Is there a way to call these functions manually at all?
You could consider when the phone is called, your application starts playing the default ring tone. Kinda hacky though
I think that you can make a broadcast receiver that senses the incoming call,So in its onReceive method you can change the settings of your phone ,hence this settings will take effects as soon as you got the call.
Hope this work.
Check out AudioManager and it shows the developing guide how to use it for changing ringing types dynamically in your application.
精彩评论