从本质上讲,标题说明了一切。我希望能够在 phonestatelistener 类中检索当前正在播放的铃声。一种解决方案可能是简单地从 RingtoneManager 检索 DEFAULT URI,但如果播放自定义联系人铃声怎么办?
到目前为止我尝试过的强制性代码片段。他们都没有返回铃声。IsPlaying 总是错误的。
public static String getPlayingRingtone() {
RingtoneManager m = new RingtoneManager(mCtx);
Cursor rings = m.getCursor();
for( int i = 0; i < rings.getCount(); i++ ) {
Ringtone tone = m.getRingtone(i);
if (tone.isPlaying() )
Log.d("Playcallringtone", "**Is playing**" + tone.getTitle(mCtx));
}
return null;
}
或者,我尝试过:
Log.d("Playcallringtone", RingtoneManager.getRingtone(mCtx,
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE)).getTitle(mCtx) + " is playing");
我的Phonestatelistener如下:
private class MyPhoneStateListener extends PhoneStateListener {
public void onCallStateChanged(int state,String number){
switch(state){
case TelephonyManager.CALL_STATE_IDLE:
// Do stuff for IDLE
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
// Do stuff of OFFHOOK
break;
case TelephonyManager.CALL_STATE_RINGING:
getPlayingRingtone();
// Do stuff for RINGING
break;
}
}
}