【发布时间】:2017-01-30 14:17:23
【问题描述】:
我在使用设备的此通话记录时遇到问题。 该代码根本没有返回日志,它给出了错误的数据。
代码:
public void ReadCalls()
{
try {
Android.Content.Context myContext = Android.App.Application.Context;
string myDateToCheck = myServiceRef.myTimeToCheck("CallLog");
if (myDateToCheck==null || myDateToCheck=="")
{myDateToCheck = "0";}
ICursor cursor = myContext.ContentResolver.Query( Android.Net.Uri.Parse ("content://call_log/calls"), null, "Date > ?", new string[]{myDateToCheck }, "Date ASC");
if (cursor.MoveToFirst ()) {
while (!cursor.IsAfterLast ) {
if (cursor.GetLong (cursor.GetColumnIndex (CallLog.Calls.Date)) > long.Parse (myDateToCheck)) {
string Number = cursor.GetString (cursor.GetColumnIndex (CallLog.Calls.Number));
string Name = cursor.GetString (cursor.GetColumnIndex (CallLog.Calls.CachedName));
if (Name == null || Name == "") {
Name = "Unknown";
}
string Date = cursor.GetString (cursor.GetColumnIndex (CallLog.Calls.Date));
string Duration = cursor.GetString (cursor.GetColumnIndex (CallLog.Calls.Duration));
string Type = cursor.GetString (cursor.GetColumnIndex (CallLog.Calls.Type));
if (Number == "0") {
Number = "Unknown";
} else if (Number == "-1") {
Number = "Unknown";
}
long num = long.Parse (Date);
Java.Text.SimpleDateFormat simpleDateFormat = new Java.Text.SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
DateTime dateTime = new DateTime (1970, 1, 1).AddMilliseconds ((double)num);
dateTime = dateTime.AddMilliseconds (simpleDateFormat.TimeZone.GetOffset (num));
if (Type == "1") {
Type = "Outgoing";
} else if (Type == "2") {
Type = "Incoming";
} else if (Type == "3") {
Type = "Missed Call";
}
// now need to write it to a database
MyCallLog myLine = new MyCallLog {
TheNumber = Number ,
TheName = Name ,
TheTime = dateTime.ToString() ,
TheDirection = Type ,
TheDuration = Duration
};
string output = Newtonsoft.Json.JsonConvert.SerializeObject (myLine );
myServiceRef.myDatabaseConnection (output);
} else {
break;
}
cursor.MoveToNext ();
}
}
}catch{
}
}
数字始终为“-1”。 名字总是空白, 而且它总是一个拨出电话。
它给出了一个日期戳但不准确。
【问题讨论】:
-
经过大量 db 搜索后,我发现这个 URI 只存储最近的数据,完整的历史记录没有存储在 URI 中,它在其他地方.. 修复了我的时间问题以及为什么 -1 但是我需要找到如何获取所有历史,网上所有的例子都没有涵盖这个
标签: c# android xamarin calllog