2010-05-04 90 views

回答

0

這似乎至少在1.6上完成了這項工作;不能確定它是否在以後的版本中支持的功能(一個是AudioManager的實例)

boolean headphones = (a.getRouting(a.getMode()) & AudioManager.ROUTE_HEADSET) == AudioManager.ROUTE_HEADSET; 
+0

@movillnescom這句話,你檢查如果耳機插入或拔出? – 2016-07-07 08:49:18

2

使用此代碼段

AudioManager am1 = (AudioManager)getSystemService(Context.AUDIO_SERVICE); 
Log.i("am1.isWiredHeadsetOn()", am1.isWiredHeadsetOn()+""); 
Log.i("am1.isMusicActive()", am1.isMusicActive()+""); 
Log.i("am1.isSpeakerphoneOn()", am1.isSpeakerphoneOn()+"");