uni-app 安卓获取通话记录 解决市面上代码出现获取不到第一条记录的问题
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); },
拿走不谢 打完收工