UNI-APP uts插件 支持ANDROID 监听手机状态

插件地址 https://ext.dcloud.net.cn/plugin?id=22646 模块

javascript 复制代码
import {
		startPhoneListener,
		stopPhoneListener,
		checkIsAutoRecord,
		toCallAutoRecorderPage,
		navigateToCallRecordingSettings,
		jumpToPermissionPage,
		makePhoneCall,
		allRecorderFilesAction,
		registerSmsReceiver,
	} from '@/uni_modules/yao-lister';

对应的权限不能忘记

javascript 复制代码
async initPhoneStateListener() {
				// 动态申请权限
				const permissions = ["android.permission.READ_PHONE_STATE",
					"android.permission.ANSWER_PHONE_CALLS", "android.permission.CALL_PHONE",
					"android.permission.MANAGE_EXTERNAL_STORAGE",
					"android.permission.READ_EXTERNAL_STORAGE",
					"android.permission.READ_CALL_LOG",
					"android.permission.READ_PHONE_NUMBERS",
					"android.permission.FOREGROUND_SERVICE",
					"android.permission.RECEIVE_SMS",
					"android.permission.READ_SMS"
				]
				const result = await plus.android.requestPermissions(permissions, 1001)

				if (result.granted) {
					startListening()
					// 监听原生事件
					uni.$on('PHONE_STATE_CHANGE', (state) => {
						this.phoneState = state
					})
				}
			}

开启,关闭电话监听

javascript 复制代码
           startListerPhone() {
				startPhoneListener(res => {
					uni.showToast({
						icon: 'success',
						title: '电话监听开启',
						duration: 2000
					});
					this.phoneState = res + "012"
				})
			},
			stopListerPhone() {
				stopPhoneListener(res => {
					uni.showToast({
						icon: 'success',
						title: res,
						duration: 2000
					});
				})
			},

其他的demo里面 可以直接查看

javascript 复制代码
allRecorderFilesAction() {
				const _this = this;
				allRecorderFilesAction(res => {
					console.log("录音文件输入", JSON.stringify(res))
					_this.toggle('bottom');
					_this.Filelist = res
					uni.showToast({
						title: JSON.stringify(res),
						duration: 2000
					})
				})
			},
			jumpToPermissionPage() {
				jumpToPermissionPage()
			},
			navigateToCallRecordingSettings() {
				navigateToCallRecordingSettings()
			},
			toCallAutoRecorderPage() {
				toCallAutoRecorderPage()
			},
			checkIsAutoRecord() {
				let checkRecord = checkIsAutoRecord()
				uni.showToast({
					title: checkRecord ? "已开启电话录音" : "未开启电话录音",
					duration: 2000
				})
			},
相关推荐
深海呐16 分钟前
Android WebView吊起软键盘遮挡输入框的问题解决
android·webview·android 键盘遮挡·webview键盘遮挡
摘星编程18 分钟前
RAG的下一站:检索增强生成如何重塑企业知识中枢?
android·人工智能
fatiaozhang952725 分钟前
基于slimBOXtv 9.19 V2(通刷S905L3A/L3AB)ATV-安卓9-通刷-线刷固件包
android·电视盒子·刷机固件·机顶盒刷机·slimboxtv9.19v2·slimboxtv
左绍骏1 小时前
01.学习预备
android·java·学习
鹏程十八少1 小时前
破解Android悬浮窗遮挡无障碍服务难题:我在可见即可说上踩过的坑
android·前端·面试
Kapaseker1 小时前
前端已死...了吗
android·前端·javascript
Winston Wood1 小时前
Android图形与显示系统经典故障解决方案:从源码到实操
android·图形系统·显示系统
Full Stack Developme2 小时前
Mycat 2 实现 MySQL 读写分离,并且实现 主从同步
android·数据库·mysql
Winston Wood2 小时前
Android图形与显示系统:从架构到协作的深度解析
android·图形系统·显示系统
lxysbly2 小时前
psx模拟器安卓版带金手指
android