有没有办法在程序中编程播放内置的音效?当我的应用程序扫描NFC标签时,我希望播放NFC声音效果(成功声音效果和失败声音效果)。
我只是从被接受的答案中复制代码,该答案在StackOverflow问题中讨论如何播放Android通知声音。
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}