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
				})
			},
相关推荐
阿pin1 天前
Android随笔-kotlin withContext
android·kotlin·withcontext
树码小子1 天前
开启 IDEA 中的断言功能
android·java·intellij-idea
Kslient1 天前
HeaderBehavior
android
Android-Flutter1 天前
android 动画详解
android·kotlin
小孔龙1 天前
GraphicBuffer 跨进程共享
android
行业研究员1 天前
Android内置GPS与腾讯地图定位技术对比分析
android·android定位·腾讯地图定位
Android-Flutter1 天前
android WMS 详解(二)
android·kotlin
游戏开发爱好者81 天前
App Store 上传 IPA 自动化,.p8 密钥认证与 CI/CD 接入实战
android·运维·ci/cd·小程序·uni-app·自动化·iphone
游戏开发爱好者81 天前
iOS 推送怎么配置,APNs 推送证书、设备库与群发
android·ios·小程序·https·uni-app·iphone·webview
阿pin2 天前
Android随笔-kotlin 高阶函数
android·kotlin·高阶函数