Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

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).

Best Answer

  • RiadRekabRiadRekab Member
    Accepted Answer

    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")
    

Answers

  • RiadRekabRiadRekab Member
    Accepted Answer

    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")
    
Sign In or Register to comment.