Search code examples
androidxamarinxamarin.formsxamarin.androidcomputer-science

Acces to SMS messages using Xamarin.Android


I want to have acces to all the SMS messages available on the Android phone and store them in a SQLITE data base , but the only solution found was using BroadcastReceiver (which is not what i am looking for).


Solution

  • I found the solution, using ContentResolver which returns a cursor of type ICursor.

    Here is the code :

      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 
            }
             
    

    Note that:

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