修改通话期间闹钟的提醒方式

android原生中,如果通话期间设定的闹钟时间到了,为了不错过闹钟同时又尽量减小对当前通话的影响,对用户设置的闹钟提醒方式进行了修改:
1. mMediaPlayer.setVolume(IN_CALL_VOLUME, IN_CALL_VOLUME);设置铃声音量为最大音量的0.125倍
2. alarmNoise = getInCallRingtoneUri(context); 播放特定的铃声(嘟嘟--嘟嘟--的声音)
 
那如果我们想要修改原生的提醒方式该到哪修改呢?

Android L

packages/apps/DeskClock/src/com/android/deskclock/alarms/AlarmKlaxon.java
 
  1.            try {
  2. // Check if we are in a call. If we are, use the in-call alarm
  3. // resource at a low volume to not disrupt the call.
  4. if (inTelephoneCall) {
  5. LogUtils.v("Using the in-call alarm");
  6. sMediaPlayer.setVolume(IN_CALL_VOLUME, IN_CALL_VOLUME);
  7. setDataSourceFromResource(context, sMediaPlayer, R.raw.in_call_alarm);
  8. } else {
  9. sMediaPlayer.setDataSource(context, alarmNoise);
  10. }
  11. startAlarm(context, sMediaPlayer);
  12. }
 
修改成通话中取消震动
 
  1. if (instance.mVibrate) {
  2. Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
  3. // Check if we are in a call. If we are, cancel the vibrator.
  4. try {
  5. if (inTelephoneCall){
  6. vibrator.cancel();
  7. }else{
  8. vibrator.vibrate(sVibratePattern, 0, VIBRATION_ATTRIBUTES);
  9. }
  10. }catch (Exception ex){
  11. }
  12. // vibrator.vibrate(sVibratePattern, 0, VIBRATION_ATTRIBUTES);
  13. }
 

Android N

7.0 上代码进行了调整,震动还是在这个类里面,铃声的设置移到了另一个类。
 
packages/apps/DeskClock/src/com/android/deskclock/alarms/AlarmKlaxon.java
 
  1. public static void start(Context context, AlarmInstance instance) {
  2. // Make sure we are stopped before starting
  3. stop(context);
  4. LogUtils.v("AlarmKlaxon.start()");
  5.  
  6. if (!AlarmInstance.NO_RINGTONE_URI.equals(instance.mRingtone)) {
  7. getAsyncRingtonePlayer(context).play(instance.mRingtone);
  8. }
  9.  
  10. if (instance.mVibrate) {
  11. final Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
  12. if (Utils.isLOrLater()) {
  13. vibrateLOrLater(vibrator);
  14. } else {
  15. vibrator.vibrate(sVibratePattern, 0);
  16. }
  17. }
  18.  
  19. sStarted = true;
  20. }
若要取消震动,在上面的代码段修改。
 
packages/apps/DeskClock/src/com/android/deskclock/ AsyncRingtonePlayer.java
 
  1. /**
  2. * Starts the actual playback of the ringtone. Executes on ringtone-thread.
  3. */
  4. @Override
  5. public boolean play(final Context context, Uri ringtoneUri) {
  6. checkAsyncRingtonePlayerThread();
  7. LogUtils.i(TAG, "Play ringtone via android.media.MediaPlayer.");
  8. ...
  9. boolean scheduleVolumeAdjustment = false;
  10. try {
  11. // Check if we are in a call. If we are, use the in-call alarm resource at a
  12. // low volume to not disrupt the call.
  13. if (isInTelephoneCall(context)) {//如果在电话中
  14. LogUtils.v("Using the in-call alarm");
  15. mMediaPlayer.setVolume(IN_CALL_VOLUME, IN_CALL_VOLUME);    //设置音量为0.125f
  16. alarmNoise = getInCallRingtoneUri(context);    //设置铃声为InCall专用铃声
  17. } else if (isCrescendoEnabled(context)) {    //如果开启“声音渐强”
  18. mMediaPlayer.setVolume(0, 0);    //先设为最小生硬(无声)
  19. // Compute the time at which the crescendo will stop.
  20. mCrescendoDuration = getCrescendoDurationMillis(context);
  21. mCrescendoStopTime = System.currentTimeMillis() + mCrescendoDuration;
  22. scheduleVolumeAdjustment = true;
  23. }
  24. // If alarmNoise is a custom ringtone on the sd card the app must be granted
  25. // android.permission.READ_EXTERNAL_STORAGE. Pre-M this is ensured at app
  26. // installation time. M+, this permission can be revoked by the user any time.
  27. mMediaPlayer.setDataSource(context, alarmNoise);
  28. startAlarm(mMediaPlayer);
  29. scheduleVolumeAdjustment = true;
  30. } catch (Throwable t) {
  31. ...
  32. }
  33. return scheduleVolumeAdjustment;
  34. }
若要定制铃声,在上面的代码段修改。
 
 
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值