安卓手机实现手机语音提示

忘记了从哪获取的方法:

/**
     * 设置提示音
     */
    public static void remindVoice() {

        YBTLog.e(TAG, "语音提醒呀");

        boolean newMessageReminder = SettingUtil.isNewMessageReminder();
        if (!newMessageReminder) {
            return;
        }

        boolean isRemingNight = SettingUtil.isNewMessageReminderInNight();
        if (!isRemingNight) {
            //夜间不提醒
            YBTLog.e(TAG, "设置的夜间不提醒");
            return;
        }

        boolean newMessageVibrationReminder = SettingUtil.isNewMessageVoiceReminder();
        if (!newMessageVibrationReminder) {
            YBTLog.e(TAG, "设置的语音不提醒");
            return;
        }

        AudioManager audioManager = (AudioManager) YBTApplication.getContext().getSystemService(Context.AUDIO_SERVICE);

        if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
            YBTLog.e("TAG", "已经调成静音");
            return;
        }

        if (ringtone == null) {
            Uri notificationUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

            ringtone = RingtoneManager.getRingtone(YBTApplication.getContext(), notificationUri);
            if (ringtone == null) {
                YBTLog.d(TAG, "cant find ringtone at:" + notificationUri.getPath());
                return;
            }
        }


        if (!ringtone.isPlaying()) {
            //String vendor = Build.MANUFACTURER;

            ringtone.play();
            // for samsung S3, we meet a bug that the phone will
            // continue ringtone without stop
            // so add below special handler to stop it after 3s if
            // needed
//            if (vendor != null && vendor.toLowerCase().contains("samsung")) {
//                Thread ctlThread = new Thread() {
//                    public void run() {
//                        try {
//                            Thread.sleep(3000);
//                            if (ringtone.isPlaying()) {
//                                ringtone.stop();
//                            }
//                        } catch (Exception e) {
//                        }
//                    }
//                };
//                ctlThread.run();
//            }
        }
    }
————————————————

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值