android 铃声 默认
场景:android 播发默认铃声和手机振动
android 播放默认铃声和手机振动
播放默认铃声:
留意以上代码:
这个其实是默认的闹钟铃声,我们可以试着去看看RingtoneManager还有哪些类型的铃声,
还有的几个分别是:
1.收到通知时的声音:
2.电话来电铃声:
手机振动效果:
开启振动:
关闭振动:
android 播放默认铃声和手机振动
播放默认铃声:
// 播放铃声 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_NOTIFICATION
2.电话来电铃声:
RingtoneManager.TYPE_RINGTONE
手机振动效果:
开启振动:
long pattern[] = { 10, 1 }; v.vibrate(pattern, 0);
关闭振动:
v.cancel();