播放默认铃声:
留意以上代码:
这个其实是默认的闹钟铃声,我们可以试着去看看RingtoneManager还有哪些类型的铃声,
还有的几个分别是:
1.收到通知时的声音:
2.电话来电铃声:
手机振动效果:
开启振动:
关闭振动:
// 播放铃声
private void ring()
{
if (player.isPlaying() || player.isLooping())
{
LogUtil.i("ck", "playing");
return;
}
try
{
Uri alert = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_ALARM);
player.setDataSource(this, alert);
final AudioManager audioManager = (AudioManager) this
.getSystemService(Context.AUDIO_SERVICE);
if (audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION) != 0)
{
player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
player.setLooping(true);
player.prepare();
player.start();
}
} catch (Exception ex)
{
}
}留意以上代码:
RingtoneManager.TYPE_ALARM这个其实是默认的闹钟铃声,我们可以试着去看看RingtoneManager还有哪些类型的铃声,
还有的几个分别是:
1.收到通知时的声音:
RingtoneManager.TYPE_NOTIFICATION2.电话来电铃声:
RingtoneManager.TYPE_RINGTONE手机振动效果:
开启振动:
long pattern[] = { 10, 1 };
v.vibrate(pattern, 0);关闭振动:
v.cancel();
本文详细介绍了如何在应用中播放默认铃声,并探讨了RingtoneManager提供的不同铃声类型,如闹钟铃声、通知铃声及电话来电铃声。通过实例代码演示了如何使用RingtoneManager来获取并播放这些铃声。
1277

被折叠的 条评论
为什么被折叠?



