


This article brings you relevant knowledge about uniapp. It mainly introduces how to use uniapp to make calls and synchronize recording. Friends who are interested should take a look at it. I hope it will be helpful to everyone. .
uniapp realizes the call recording function
Recently, I need to implement a function of calling the mobile phone to make a call through uniapp. After making the call, it will be recorded at the same time. After hanging up the call, Upload the recording file and now share some core codes with everyone!
const recorderManager = uni.getRecorderManager(); onLoad(option) { let self = this; recorderManager.onStop(function (res) { console.log("res",res) self.end_time = Math.round(new Date().getTime() / 1000); let voicePath = res.tempFilePath; self.voicePath = voicePath; self.closeTimeOut(); uni.showToast({ icon: 'loading', title: "请稍后...", duration: 0 }); uni.uploadFile({ url: self.upload_url, filePath: voicePath, name: "file", formData: { id: self.phoneInfo.id, start_time: self.start_time, end_time: self.end_time, phone: self.phoneNumber }, header: { Authorization: "Bearer " + uni.getStorageSync(EnumData.token) }, success: (res) => { // console.log("文件上传成功") console.log(res.data); }, fail(err) { console.log("文件上传失败") console.log(err); }, complete() { self.start_time = 0; self.end_time = 0; uni.hideToast(); } }) }); this.getCallStatus(); } getCallStatus() { let that = this; let maintest = plus.android.runtimeMainActivity(); let Contexttest = plus.android.importClass("android.content.Context"); let telephonyManager = plus.android.importClass("android.telephony.TelephonyManager"); let telManager = plus.android.runtimeMainActivity().getSystemService(Contexttest.TELEPHONY_SERVICE); let receiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', { onReceive: function (Contexttest, intent) { plus.android.importClass(intent); let phoneStatus = telManager.getCallState(); that.callStatus = phoneStatus; //电话状态 0->空闲状态 1->振铃状态 2->通话存在 switch (phoneStatus) { case 0: console.log("3、电话挂断,上传录音") // 结束录音 recorderManager.stop(); break; case 1: // console.log('1、振铃状态'); break; case 2: console.log('2、通话存在') // 延迟录音 that.start_time = Math.round(new Date().getTime() / 1000); recorderManager.start({ duration: EnumData.audioDuration, // 时长 10分钟 sampleRate: EnumData.audioSampleRate, // 码率 }); break; } } }); let IntentFilter = plus.android.importClass('android.content.IntentFilter'); let filter = new IntentFilter(); filter.addAction(telephonyManager.ACTION_PHONE_STATE_CHANGED); maintest.registerReceiver(receiver, filter); },
The permissions you need to apply for can be placed in App.vue
if (plus.os.name == 'Android') { plus.android.requestPermissions( ['android.permission.ANSWER_PHONE_CALLS',//手动 挂断和接听 需要这个权限 "android.permission.MODIFY_AUDIO_SETTINGS",//手动 挂断和接听 需要这个权限 "android.permission.CALL_PHONE",//手动 挂断和接听 需要这个权限 "android.permission.READ_PHONE_STATE",//>监听电话状态 需要这个权限 "android.permission.READ_CALL_LOG",//获取号码需要这个权限 "android.permission.READ_AUDIO" // 录音权限 ], function(resultObj) { var result = 0; for (var i = 0; i < resultObj.granted.length; i++) { var grantedPermission = resultObj.granted[i]; console.log('已获取的权限:' + grantedPermission); result = 1 } for (var i = 0; i < resultObj.deniedPresent.length; i++) { var deniedPresentPermission = resultObj.deniedPresent[i]; console.log('拒绝本次申请的权限:' + deniedPresentPermission); result = 0 } for (var i = 0; i < resultObj.deniedAlways.length; i++) { var deniedAlwaysPermission = resultObj.deniedAlways[i]; console.log('永久拒绝申请的权限:' + deniedAlwaysPermission); result = -1 } }, function(error) { console.log('申请权限错误:' + error.code + " = " + error.message); } ); }
Note
It can be used in debug mode It normally monitors call hang-ups and uploads files, but it becomes invalid after packaging?
General mobile phone packaging can be used normally. I use oneplus7. After packaging, it can be installed and used normally. Some mobile phones need to go to the permissions of the system settings and change the application's [Open the phone [Device Status Code] Just turn it on. This is what I have encountered so far.
Recommended learning: "uni-app video tutorial"
The above is the detailed content of Detailed example of how uniapp implements phone recording function (with code). For more information, please follow other related articles on the PHP Chinese website!

VSCode中如何开发uni-app?下面本篇文章给大家分享一下VSCode中开发uni-app的教程,这可能是最好、最详细的教程了。快来看看!

如何利用uniapp开发一个贪吃蛇小游戏?下面本篇文章就手把手带大家在uniapp中实现贪吃蛇小游戏,希望对大家有所帮助!

uni-app接口,全局方法封装1.在根目录创建一个api文件,在api文件夹中创建api.js,baseUrl.js和http.js文件2.baseUrl.js文件代码exportdefault"https://XXXX.test03.qcw800.com/api/"3.http.js文件代码exportfunctionhttps(opts,data){lethttpDefaultOpts={url:opts.url,data:data,method:opts.method

本篇文章手把手带大家开发一个uni-app日历插件,介绍下一款日历插件是如何从开发到发布的,希望对大家有所帮助!

本篇文章给大家带来了关于uniapp的相关知识,其中主要整理了实现多选框的全选功能的相关问题,无法实现全选的原因是动态修改checkbox的checked字段时,界面上的状态能够实时变化,但是无法触发checkbox-group的change事件,下面一起来看一下,希望对大家有帮助。

uniapp怎么实现scroll-view下拉加载?下面本篇文章聊聊uniapp微信小程序scroll-view的下拉加载,希望对大家有所帮助!

本篇文章给大家带来了关于uniapp的相关知识,其中主要介绍了怎么用uniapp实现拨打电话并且还能同步录音的功能,感兴趣的朋友一起来看一下吧,希望对大家有帮助。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 English version
Recommended: Win version, supports code prompts!

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools