Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Xamarin Mobile Development for Android Cookbook

You're reading from   Xamarin Mobile Development for Android Cookbook Over 80 hands-on recipes to unleash full potential for Xamarin in development and monetization of feature-packed, real-world Android apps

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher
ISBN-13 9781784398576
Length 456 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Matthew Leibowitz Matthew Leibowitz
Author Profile Icon Matthew Leibowitz
Matthew Leibowitz
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Working with Xamarin.Android FREE CHAPTER 2. Showing Views and Handling Fragments 3. Managing App Data 4. Presenting App Data 5. Communicating with the Outside World 6. Using Background Tasks 7. Notifying Users 8. Interacting with Other Apps 9. Presenting Multimedia 10. Responding to the User 11. Connecting to Wearables 12. Adding In-App Billing 13. Publishing Apps Index

Receiving SMS messages


Our app may be using SMS messages to verify the phone number that the user has specified. If we want to do this, we may want to listen for an incoming SMS message.

How to do it...

To listen for incoming SMS messages, we will use a broadcast receiver:

  1. First, we will need a permission to receive SMS messages:

    [assembly: UsesPermission(Manifest.Permission.ReceiveSms)]
  2. Next, we will need a broadcast receiver that listens for incoming messages:

    [BroadcastReceiver]
    [IntentFilter(
      new[] { "android.provider.Telephony.SMS_RECEIVED" })]
    public class SmsReceiver : BroadcastReceiver {
      public override void OnReceive(
      Context context, Intent intent) {
      }
    }
  3. Finally, we process the incoming intent and read the SMS message:

    if (intent.HasExtra("pdus")) {
      var smsArray = (Java.Lang.Object[])intent.Extras.Get("pdus");
      string address = "";
      string message = "";
      foreach (var item in smsArray) {
        var sms = SmsMessage.CreateFromPdu((byte[])item);
        message += sms.MessageBody;
    ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image