Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8985027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:14:48+00:00 2026-06-15T21:14:48+00:00

I wrote send and receive program in android. when sms received from special number,

  • 0

I wrote send and receive program in android. when sms received from special number, sms go to my program and body of sms , show in text. but for received sms from other phone number, sms go to inbox of phone and program isn’t opened.
Now in my program , for every received sms, program is opened and body of sms is shown in textview.
if condition didn’t work!!!
i put my code, please check my code.
SmsReceiver.java

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
public class SmsReceiver extends BroadcastReceiver {
    public String str = "";
    static final String ACTION =
            "android.provider.Telephony.SMS_RECEIVED";
    @Override
    public void onReceive(Context context, Intent intent) {
         if (intent.getAction().equals(ACTION)) {       
        Bundle bundle = intent.getExtras();
        SmsMessage[] msgs = null;
        if (bundle != null) {                   
            Object[] pdus = (Object[]) bundle.get("pdus");
            msgs = new SmsMessage[pdus.length];

            for (int i = 0; i < msgs.length; i++) 
            {
                msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);               
                String msg_from = msgs[i].getOriginatingAddress();    
                if(msg_from.equals("+9891--------"))
                {
                str += "SMS from " + msgs[i].getOriginatingAddress();
                str += " :";
                str += msgs[i].getMessageBody().toString();
                str += "\n";
               }
            }
            Intent act = new Intent(context, MainActivity.class);
            act.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            act.putExtra("message", str);
            context.startActivity(act);
            }
        abortBroadcast();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:14:49+00:00Added an answer on June 15, 2026 at 9:14 pm

    You should do the context.startActivity(act); in the if condition. I think you mistakenly put it out of the if condition.
    Also the abortBroadcast() should be in if condition coz that makes sense, if the msg is not from the special number it should go to the inbox….RIGHT 🙂

    Edited:

    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(ACTION)) {
            Bundle bundle = intent.getExtras();
            SmsMessage[] msgs = null;
            if (bundle != null) {
                Object[] pdus = (Object[]) bundle.get("pdus");
                msgs = new SmsMessage[pdus.length];
    
                for (int i = 0; i < msgs.length; i++) {
                    msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                    String msg_from = msgs[i].getOriginatingAddress();
                    if (msg_from.equals("+9891--------")) {
                        String str = "SMS from " + msgs[i].getOriginatingAddress();
                        str += " :";
                        str += msgs[i].getMessageBody().toString();
                        str += "\n";
                        Intent act = new Intent(context, MainActivity.class);
                        act.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        act.putExtra("message", str);
                        context.startActivity(act);
                        abortBroadcast();
                    }
                }
    
            }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a simple send and receive UDP program working, but I'm
I wrote application, that receive SMS. In the AndroidManifest.xml I wrote: <receiver android:name=.SmsReceiver> <intent-filter>
I wrote some codes so as to send e mail but I can only
I am using Ubuntu 12.04 32 bit edition I wrote a program to receive
I wrote a program using tcpip sockets to send commands to a device and
I've written two programs. Now each program uses threading to send and receive packets
Alright, I'm trying to set a program I have to receive data from a
I'm trying to receive a variable length stream from a camera with python, but
I want to send a few gyroscope readings from my android device to a
I am having a problems trying to send a file from a server program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.