zoukankan      html  css  js  c++  java
  • (简单实用)Android支付宝商家收款语音播报

    支付宝商家收款时,语音提示:支付宝收款xxx元,当时觉得这东西还挺有趣的,第一时间通知给商家,减少不必要的纠纷,节约时间成本,对商家对用户都挺好的。
    在商家版有这样收款播报的功能,我觉得挺好的。
    对列处理及电话中断已经处理。
     

    使用

    1. gradle引入
       allprojects {
            repositories {
            ...
                maven { url 'https://jitpack.io' }
            }
        }
    
        dependencies {
            implementation 'com.github.YzyCoding:PushVoiceBroadcast:1.0.2'
        }
    1. 一行代码引用
      VoicePlay.with(MainActivity.this).play(amount);


    需求

    • 固定播报文字,除了金额动态
    • 收到多条推送,顺序播报
    • 来电时,暂停播报,挂断后继续播报
    • 正在播放音乐,暂停音乐,播放完成继续播放音乐
    • 如果音量过小,调节音量

    思路

    • 金额转大写
    • 文字转音频
    • 顺序播放

    实践

    1. 关于金额的工具类
    public class MoneyUtils {
    
        private static final char[] NUM = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
        private static final char[] CHINESE_UNIT = {'元', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟'};
    
        /**
         * 返回关于钱的中文式大写数字,支仅持到亿
         */
        public static String readInt(int moneyNum) {
            String res = "";
            int i = 0;
            if (moneyNum == 0) {
                return "0";
            }
    
            if (moneyNum == 10) {
                return "拾";
            }
    
            if (moneyNum > 10 && moneyNum < 20) {
                return "拾" + moneyNum % 10;
            }
    
            while (moneyNum > 0) {
                res = CHINESE_UNIT[i++] + res;
                res = NUM[moneyNum % 10] + res;
                moneyNum /= 10;
            }
    
            return res.replaceAll("0[拾佰仟]", "0")
                    .replaceAll("0+亿", "亿")
                    .replaceAll("0+万", "万")
                    .replaceAll("0+元", "元")
                    .replaceAll("0+", "0")
                    .replace("元", "");
        }
    }

    容错处理

        /**
         * 提取字符串中的 数字 带小数点 ,没有就返回""
         *
         * @param money
         * @return
         */
        public static String getMoney(String money) {
            Pattern pattern = Pattern.compile("(\d+\.\d+)");
            Matcher m = pattern.matcher(money);
            if (m.find()) {
                money = m.group(1) == null ? "" : m.group(1);
            } else {
                pattern = Pattern.compile("(\d+)");
                m = pattern.matcher(money);
                if (m.find()) {
                    money = m.group(1) == null ? "" : m.group(1);
                } else {
                    money = "";
                }
            }
    
            return money;
        }

     by: 杨



  • 相关阅读:
    Android LogCat使用详解
    新时代新潮流WebOS 【20】WebKit的结构与解构
    Android调试的必杀技——反汇编
    真机缺少com.google.android.maps.jar解决方法:
    test
    VMware让ubuntu与win7共享文件方法
    android手机通过笔记本无线wifi上网
    新时代新潮流WebOS 【22】WebKit,鼠标引发的故事
    获取证书
    获取局域网内部机器的MAC地址
  • 原文地址:https://www.cnblogs.com/widgetbox/p/yanger.html
Copyright © 2011-2022 走看看