1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram

  5. Delphifan Magazine
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Intercept SMS with Broadcast Receiver

Discussion in 'Delphi Android And IOS' started by AdminDF, Aug 26, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    Hi developers,

    in Android Broadcast Receivers are used to listen for broadcast Intents. A Broadcast Receiver needs to be registered, either in code or within the application manifest. (in this case is registered in the manifest)
    When registering a Broadcast Receiver you must use an Intent Filter to specify which Intents it is listening for.

    We use BroadcastReceiver to intercept SMS.
    See the code below


    Code:
    01
    import android.content.BroadcastReceiver;
    02
    import android.content.Context;
    03
    import android.content.Intent;
    04
    import android.os.Bundle;
    05
    import android.telephony.SmsMessage;
    06
    import android.widget.Toast;
    07
     
    08
    public class SMSBroadcastReceiver extends BroadcastReceiver{
    09
            @Override
    10
     public void onReceive(Context context, Intent intent) {
    11
      Bundle bundle = intent.getExtras();
    12
      SmsMessage[] msgs = null;
    13
      StringBuilder str = new StringBuilder();
    14
      if (bundle != null) {
    15
       // --- retrieve the received SMS here ---
    16
       Object[] pdus = (Object[]) bundle.get("pdus");
    17
       msgs = new SmsMessage[pdus.length];
    18
       for (int i = 0; i < msgs.length; i++) {
    19
        msgs = SmsMessage.createFromPdu((byte[]) pdus);
    20
        str.append("SMS from " + msgs.getOriginatingAddress());
    21
        str.append(" :");
    22
        str.append(msgs.getMessageBody().toString());
    23
        str.append("\n");
    24
       }
    25
       // ...we show sms here...
    26
       Toast.makeText(context, str.toString(), Toast.LENGTH_SHORT).show();
    27
      }
    28
     }
    29
    }
    
     
    Mahdi and XoreDev like this.
  2. delphipure
    Offline

    delphipure Guest

  3. Cimasim89
    Offline

    Cimasim89 DF Member

    interesting
     

Share This Page