z***@Outlook.com
z***@Outlook.com
  • 发布:2024-08-22 11:57
  • 更新:2024-11-01 13:33
  • 阅读:292

uniApp获取通话记录

分类:uni-app

uniApp获取通话记录

首先讲一个大坑

要拿到通过记录真机调试时候必须前给足权限,必须打包成自定义基座再测试!!!!!!一定要先打包!!!!

必要权限

首先勾取manifest.json里APP模块里通讯录权限
添加以下权限

<uses-feature android:name="android.permission.READ_CONTACTS"/>  
<uses-permission android:name="android.permission.READ_CALL_LOG"/>

为了怕遗漏我把我所有的权限都放出来提供参考

<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>  
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>  
<uses-permission android:name="android.permission.VIBRATE"/>  
<uses-permission android:name="android.permission.READ_LOGS"/>  
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>  
<uses-feature android:name="android.hardware.camera.autofocus"/>  
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>  
<uses-permission android:name="android.permission.CAMERA"/>  
<uses-permission android:name="android.permission.CALL_PHONE"/>  
<uses-feature android:name="android.permission.READ_CONTACTS"/>  
<uses-permission android:name="android.permission.READ_CALL_LOG"/>  
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>  
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>  
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>  
<uses-permission android:name="android.permission.WAKE_LOCK"/>  
<uses-permission android:name="android.permission.FLASHLIGHT"/>  
<uses-feature android:name="android.hardware.camera"/>  
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>  
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>  
<uses-permission android:name="android.permission.READ_CONTACTS"/>  

然后打包制作自定义基座

获取通话记录代码

我也是从其他地方粘的

getCalllog(){  
                var CallLog = plus.android.importClass('android.provider.CallLog');  
                var Activity = plus.android.runtimeMainActivity();  
                var ContentResolver = plus.android.importClass('android.content.ContentResolver');  
                var resolver = Activity.getContentResolver();  
                plus.android.importClass(resolver);  
                var String = plus.android.importClass("java.lang.String");  
                var cs = resolver.query(CallLog.Calls.CONTENT_URI, null, null, null, CallLog.Calls.DEFAULT_SORT_ORDER);  
                var talist = [];  
                uni.showLoading({  
                    title: "匹配通话记录中.."  
                });  
                var count = 0; // 记录多少条 用于处理循环跳出  
                while (plus.android.invoke(cs, "moveToNext")) {  
                    count++;  
                    talist.push({  
                        xm: plus.android.invoke(cs, "getString", plus.android.invoke(cs, "getColumnIndex", CallLog.Calls.CACHED_NAME)),  
                        telphone: plus.android.invoke(cs, "getString", plus.android.invoke(cs, "getColumnIndex", CallLog.Calls.NUMBER)),  
                        duration: plus.android.invoke(cs, "getString", plus.android.invoke(cs, "getColumnIndex", CallLog.Calls.DURATION)),  
                        date: plus.android.invoke(cs, "getString", plus.android.invoke(cs, "getColumnIndex", CallLog.Calls.DATE)),  
                        type: plus.android.invoke(cs, "getString", plus.android.invoke(cs, "getColumnIndex", CallLog.Calls.TYPE))  
                    });  
                    if(count > 50){  
                        break;  
                    }  
                }  
                uni.hideLoading();  
                console.info("talist",talist);  
            },
1 关注 分享
leaf666

要回复文章请先登录注册

leaf666

leaf666

太牛皮了
2024-11-01 13:33
z***@grjjr.com

z***@grjjr.com

ios 能获取么?
2024-10-28 16:00