Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

I am created BroadcastReceiver in ListView but not working.this is my code

AnbuMani27AnbuMani27 USMember ✭✭✭


SmsReceiver Class:

[BroadcastReceiver(Enabled = true, Label = "SMS Receiver")]
[IntentFilter(new[] { "android.provider.Telephony.SMS_RECEIVED" })]

public class SmsReceiver : BroadcastReceiver
private const string Tag = "SMSBroadcastReceiver";
private const string IntentAction = "android.provider.Telephony.SMS_RECEIVED";
public override void OnReceive(Context context, Intent intent)
Log.Info(Tag, "Intent received: " + intent.Action);
if (intent.Action != IntentAction) return;
var bundle = intent.Extras;
if (bundle == null) return;
var pdus = bundle.Get("pdus");
var castedPdus = JNIEnv.GetArray<Java.Lang.Object>(pdus.Handle);
var msgs = new SmsMessage[castedPdus.Length];
var sb = new StringBuilder();
for (var i = 0; i < msgs.Length; i++)
var bytes = new byte[JNIEnv.GetArrayLength(castedPdus[i].Handle)];
JNIEnv.CopyArray(castedPdus[i].Handle, bytes);
msgs[i] = SmsMessage.CreateFromPdu(bytes);
sb.Append(string.Format("SMS From: {0}{1}Body: {2}{1}", msgs[i].OriginatingAddress,
Environment.NewLine, msgs[i].MessageBody));
Toast.MakeText(context, sb.ToString(), ToastLength.Long).Show();
SmshomeActivity msg=SmshomeActivity.Instance();


private static SmshomeActivity inst;
ArrayAdapter arrayAdapter;
List smsMessagesList = new List();
ListView smsListView;

public static SmshomeActivity Instance()
return inst;

protected override void OnStart()
Log.Debug(LogTag, "SmsReceiver");
inst = this;
protected override void OnCreate(Bundle savedInstanceState)
// Create your application here
smsListView = (ListView)FindViewById(Resource.Id.txtlistsms);
arrayAdapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, smsMessagesList);
smsListView.ItemClick += SmsListView_ItemClick;
private void SmsListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
var a = smsMessagesList[e.Position].FirstOrDefault();

public void updateList(string smsMessage)
arrayAdapter.Insert(smsMessage, 0);

Best Answer


Sign In or Register to comment.