locked
Read and receive SMS From Devices RRS feed

  • Question

  • User287570 posted

    Hi All,

    I want to read and receive SMS from my devices using Xamarin.Forms(Android & iOS)

    Is there any one have an idea how to I implement?

    Please guide me.

    Monday, May 1, 2017 8:33 AM

All replies

  • User53097 posted

    https://github.com/cjlotz/Xamarin.Plugins

    Android read SMS: http://stackoverflow.com/questions/848728/how-can-i-read-sms-messages-from-the-device-programmatically-in-android http://stackoverflow.com/questions/7089313/android-listen-for-incoming-sms-messages

    // public static final String INBOX = "content://sms/inbox"; // public static final String SENT = "content://sms/sent"; // public static final String DRAFT = "content://sms/draft"; Cursor cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);

    if (cursor.moveToFirst()) { // must check the result to prevent exception do { String msgData = ""; for(int idx=0;idx

    iOS: Send but not read.

    Monday, May 1, 2017 6:12 PM
  • User170395 posted

    Will this approach work if I'm trying to extract a v-card from SMS?

    Thursday, October 26, 2017 7:00 PM
  • User378432 posted

    You need to request permissions in manifest to receive sms: <uses-permission android:name="android.permission.RECEIVE_SMS"/>

    Write a broadcast receiver:

    using Android.App;
    using Android.Content;
    using Android.OS;
    using Android.Provider;
    using Android.Telephony;
    using Android.Util;
    using System;
    
    namespace ActivityAlert.Droid
    {
        [BroadcastReceiver(Enabled = true, Exported = true)]
        [IntentFilter(new[] { "android.provider.Telephony.SMS_RECEIVED" })]
        class SmsReceiver : BroadcastReceiver
        {
            private const string TAG = "AA:SmsReceiver";
            public override void OnReceive(Context context, Intent intent)
            {
    
                if (intent.Action.Equals(Telephony.Sms.Intents.SmsReceivedAction))
                {
                    var msgs = Telephony.Sms.Intents.GetMessagesFromIntent(intent);
                    foreach( var msg in msgs)
                    {
                        Log.Debug(TAG, $" MessageBody {msg.MessageBody}");
                        Log.Debug(TAG, $"DisplayOriginatingAddress {msg.DisplayOriginatingAddress}");
                        Log.Debug(TAG, $"OriginatingAddress {msg.OriginatingAddress}");
                    }
                }
    
            }
    
        }
    }
    
    Monday, October 8, 2018 12:57 PM
  • User223656 posted

    @AndrewMcCormack said: https://github.com/cjlotz/Xamarin.Plugins

    Android read SMS: http://stackoverflow.com/questions/848728/how-can-i-read-sms-messages-from-the-device-programmatically-in-android http://stackoverflow.com/questions/7089313/android-listen-for-incoming-sms-messages

    // public static final String INBOX = "content://sms/inbox"; // public static final String SENT = "content://sms/sent"; // public static final String DRAFT = "content://sms/draft"; Cursor cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);

    if (cursor.moveToFirst()) { // must check the result to prevent exception do { String msgData = ""; for(int idx=0;idx

    iOS: Send but not read.

    Can I have the Xamarin Version of this Code?

    Wednesday, January 22, 2020 9:57 AM
  • User397434 posted

    Have you ever found the Xamarin version of this code?

    Thursday, October 22, 2020 10:23 AM