gpt4 book ai didi

java - Android 中如何停止铃声闹钟?

转载 作者:太空宇宙 更新时间:2023-11-04 09:12:04 24 4
gpt4 key购买 nike

我在 Android 中为通知制作了闹钟播放。但是如何在 Android 中制作停止按钮呢?启动闹钟的代码:

public void playRingtone(View view) {
try {
Uri path = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.song);
RingtoneManager.setActualDefaultRingtoneUri(
getApplicationContext(), RingtoneManager.TYPE_ALARM, path
);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), path);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
}

最佳答案

 RingtoneManager ringtoneManager = new RingtoneManager(getContext());

public void playRingtone(View view) {
try {
Uri path = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.song);
ringtoneManager.setActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_ALARM, path);
Ringtone r = ringtoneManager.getRingtone(getApplicationContext(), path);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
}

public void stopRingtone(){
ringtoneManager.stopPreviousRingtone();
}

关于java - Android 中如何停止铃声闹钟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59557991/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com