uni-app获取通话记录 自定义基座打包能成功获取

 

// 获取通话记录
				var CallLog = plus.android.importClass("android.provider.CallLog");
				
				var main = plus.android.runtimeMainActivity();
				var obj = main.getContentResolver();
				plus.android.importClass(obj);
				//查询
				var cursor = obj.query(
					CallLog.Calls.CONTENT_URI,
					null,
					null,
					null,
					null
				);
				plus.android.importClass(cursor);
				var content = []; // 用来存储数据
				var count = 0; // 记录多少条
				if (cursor.moveToFirst()) {
					while (cursor.moveToNext()) {
						count++;
						//号码
						var number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));
						//呼叫类型
						var type;
						switch (
							parseInt(cursor.getString(cursor.getColumnIndex(CallLog.Calls.TYPE))))
						// 判断通话类型
						{
							case CallLog.Calls.INCOMING_TYPE:
								type = "呼入";
								break;
							case CallLog.Calls.OUTGOING_TYPE:
								type = "呼出";
								break;
							case CallLog.Calls.MISSED_TYPE:
								type = "未接";
								break;
							default:
								type = "挂断"; //应该是挂断.根据我手机类型判断出的
								break;
						}
						// 获取时间
						var date = new Date(parseInt(
							cursor.getString(cursor.getColumnIndexOrThrow(CallLog.Calls.DATE))));
						// 联系人
						var Name_Col = cursor.getColumnIndexOrThrow(CallLog.Calls.CACHED_NAME);
						var name = cursor.getString(Name_Col);
						// 号码归属地 返回:北京 联通
						var numberLocation = cursor.getString(
							cursor.getColumnIndex(CallLog.Calls.GEOCODED_LOCATION)
						);
						//通话时间,单位:s
						var Duration_Col = cursor.getColumnIndexOrThrow(CallLog.Calls.DURATION);
						var duration = cursor.getString(Duration_Col);
						// 存入数组 
						content.push({
							name: name, // 联系人的姓名
							mobile: number, // 联系人电话
							numberLocation: numberLocation, // 号码的归属地
							callTime: new Date().getTime(date), // 呼入或呼出时间
							talkTime: duration, // 通话时长
							type: type
						});
						// 查询50条 就跳出
						if (count > 50) {
							break;
						}
					}
				}
				console.log(JSON.stringify(content));

 

mainfet.json里加

"",

""

 

你可能感兴趣的:(uni-app获取通话记录 自定义基座打包能成功获取)