使用 Xamarin.Android 访问短信

Acces to SMS messages using Xamarin.Android

我想访问 Android phone 上可用的所有 SMS 消息并将它们存储在 SQLITE 数据库中,但找到的唯一解决方案是使用 BroadcastReceiver(这不是什么我正在寻找)。

我找到了解决方案,使用 returns 类型为 ICursor 的游标的 ContentResolver。

这是代码:

  Android.Database.ICursor cursor = ContentResolver.Query(uri, null, null, null,null);
  
  StringBuilder stri = new StringBuilder("");
        while(cursor.MoveToNext())
        {
            stri.Append(cursor.GetString(0));
            //Do what ever you want 
        }
         

注意:

  uri =Android.Net.Uri.Parse("content://sms/inbox")