在 Android 上,我在尝试确定实际播放的是哪个铃声时遇到了问题(我不是要检测默认铃声,但实际播放的铃声可能会有所不同,因为用户为特定铃声设置了特定铃声)接触)。
我正在使用 Ringtone.isPlaying() 函数,因为我从 RingtoneManager 循环(成功地)所有可用的铃声。然而,它们都没有返回 true 给 Ringtone.isPlaying()!任何人都知道我做错了什么?这是在环播放时肯定正在运行的代码示例:
RingtoneManager rm = new RingtoneManager(this); // 'this' is my activity (actually a Service in my case)
if (rm != null)
{
Cursor cursor = rm.getCursor();
cursor.moveToFirst();
for (int i = 0; ; i++)
{
Ringtone ringtone = rm.getRingtone(i); // get the ring tone at this position in the Cursor
if (ringtone == null)
break;
else if (ringtone.isPlaying() == true)
return (ringtone.getTitle(this)); // *should* return title of the playing ringtone …Run Code Online (Sandbox Code Playgroud)