Delphi Android 获取通�记录


本文整理自网络,侵删。

 
uses
  Androidapi.Helpers,
  Androidapi.JNI.GraphicsContentViewText,
  Androidapi.JNI.Provider;

var
  Cursor: JCursor;
  Name: string;
begin
  Cursor := TAndroidHelper.Activity.getContentResolver.query(
    TJCallLog_Calls.JavaClass.CONTENT_URI,
    nil,
    nil,
    nil,
    nil);
  if Cursor.moveToFirst then
  begin
    while True do
    begin
      Name := JStringToString
        (Cursor.getString(Cursor.getColumnIndex(StringToJString('NAME'))));
      Memo1.Lines.Add(Name);
      if not Cursor.moveToNext then
        Exit;
    end;
  end;
end;



完善一下:
uses
  System.DateUtils,
  Androidapi.Helpers,
  Androidapi.JNI.GraphicsContentViewText,
  Androidapi.JNI.Provider;

var
  Cursor: JCursor;
  Name: string;
  UnixDate: Int64;
  Date: TDateTime;
  Selection: string;
begin
  // 2016年4月1日至2016年6月1日
  Selection := Format(
    'DATE>%d and DATE<%d',
    [DateTimeToUnix(EncodeDate(2016, 4, 1)) * 1000,
    DateTimeToUnix(EncodeDate(2016, 6, 1)) * 1000]);

  // 3用参数定义条件
  Cursor := TAndroidHelper.Activity.getContentResolver.query(
    TJCallLog_Calls.JavaClass.CONTENT_URI,
    nil,
    StringToJString(Selection),
    nil,
    nil);
  if Cursor.moveToFirst then
  begin
    while True do
    begin
      Name := JStringToString
        (Cursor.getString(Cursor.getColumnIndex(StringToJString('NAME'))));
      UnixDate := Cursor.getLong
        (Cursor.getColumnIndex(StringToJString('DATE')));
      Date := UnixToDateTime(UnixDate div 1000);
      Memo1.Lines.Add(Name + ' ' + FormatDateTime('yyyy/mm/dd hh:nn:ss', Date));

      if not Cursor.moveToNext then
        Exit;
    end;
  end;
end;

相关阅读 >>

Delphi encodeuricomponent

Delphi http协议验证访问datasnap rest 服务器

Delphi 全盘搜索指定文件

Delphi转换 tcolor 到 html 颜色串

Delphi多线程程序示例(最简单的多线程)

Delphi dbnavigator1 模拟点击

Delphi android下拉刷新

Delphi trayicon控件,如何实现窗口最小化的时候到系统托盘?

Delphi实现电脑端微信图片文件解密

Delphi屏蔽alt+tab键代码

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...