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 6800377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:57:42+00:00 2026-05-26T18:57:42+00:00

Hello I faced the same problem I have 1 broadcast receiver from that I

  • 0

Hello I faced the same problem I have 1 broadcast receiver from that I started 1 service which is for getting messages from inbox. After that from that service I send those messages to the particular number. And for the sending message I used the same code as above(posted by John). My problem is, when I send message the toast Message “SMS SENT” will come continuously. So how can I receive that only once?

I am stuck on this please can anybody suggest me where I am wrong?

Thanks.

Here I posted my code:-

package z.z.z;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;

public class SMSReceiver extends BroadcastReceiver  
{
    private SmsMessage[] msgs;
    private String strNo,strMsgText;

    @Override
    public void onReceive(Context context, Intent intent) 
    {
        try
        {
            Bundle bundle = intent.getExtras();        
            msgs = null;
            String str = "";         

            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]);
                    str += "SMS from " + msgs[i].getOriginatingAddress();                     
                    str += ":";
                    str += msgs[i].getMessageBody().toString();
                    str += "\n";
                    strNo = msgs[i].getOriginatingAddress();    
                    strMsgText = msgs[i].getDisplayMessageBody();

                }

                context.startService(new Intent(context,IncomingSMSService.class));

            }
        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }
    }

}

IncomingSMSService:-

package z.z.z;

import java.util.ArrayList;

import z.z.z.Global;
import z.z.z.SMSService;

import android.app.Service;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.IBinder;
import android.util.Log;

public class IncomingSMSService extends Service  
{

    private String TAG = "IncomingSMSService";

    @Override
    public IBinder onBind(Intent intent)
    {
        return null;
    }

    @Override
    public void onCreate() 
    {
        /* start service */

        Log.d(TAG ,"****** in service onCreate  **----- ");
        super.onCreate();

        try
        {
            Log.d(TAG ,"****** in service try  **----- ");
            /* Read SMS from INBOX  */
            Uri uriSMSURI = Uri.parse("content://sms/inbox");      
            Cursor cur = getContentResolver().query(uriSMSURI, null, null, null,null);      
            String sms = "";      
            while (cur.moveToNext()) 
            {          
                    sms += "From :" + cur.getString(2) + " : " + cur.getString(11)+"\n";
    //              Log.d(TAG, "in SMS Service sms in loop :: "+ sms);
            }
            Log.d(TAG, "in SMS Service sms :: "+ sms);


            Log.d(TAG ,"********** reverseNum ******  "+ Global.destNo);
            ArrayList<String> ayyMsg = new ArrayList<String>();
            ayyMsg.add(sms);
            SMSService.sendSMS(getBaseContext(), ayyMsg, Global.destNo);
        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }
    }}

SendSMS

   package z.z.z;

    import java.util.ArrayList;

    import z.z.z.common.RMAReceiver;

    import android.app.PendingIntent;
    import android.content.Context;
    import android.content.Intent;
    import android.content.IntentFilter;
    import android.telephony.SmsManager;
    import android.util.Log;

    public class SMSService 
    {

        static String TAG = "SMSService";
        static String SENT = "SMS_SENT";
        static String DELIVERED = "SMS_DELIVERED";

    //  static Context mContext;
        static RMAReceiver rmaReceiver = null;
        public static void sendSMS(Context context,ArrayList<String> message, String destNumber)
        {   
            try
            {



                PendingIntent sentPI = PendingIntent.getBroadcast(context, 0,new Intent(SENT), 0);

                PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0,new Intent(DELIVERED), PendingIntent.FLAG_CANCEL_CURRENT);

                ArrayList<PendingIntent> ayySentPI = new ArrayList<PendingIntent>();
                ayySentPI.add(sentPI);

                ArrayList<PendingIntent> ayyDeliveredPI = new ArrayList<PendingIntent>();
                ayyDeliveredPI.add(deliveredPI);

                receiver(context);

                SmsManager sms = SmsManager.getDefault();

                sms.sendMultipartTextMessage(destNumber, null, message, ayySentPI, ayyDeliveredPI);

            }
            catch (Exception e) 
            {
                e.printStackTrace();
            }
        }

**receiver**:-

    public static void receiver(Context context)
        {
            rmaReceiver = RMAReceiver.getSingleInstance();
            context.registerReceiver(rmaReceiver, new IntentFilter(SENT));

            //---when the SMS has been delivered---
            context.registerReceiver(rmaReceiver, new IntentFilter(DELIVERED));  
        }

RMAReceiver

package z.z.z;

import z.z.z.SMSService;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;
import android.widget.Toast;

public class RMAReceiver extends BroadcastReceiver 
{
    private static RMAReceiver singleInstance = null;
    String msg;

    private RMAReceiver()
    {       
    }

    public static RMAReceiver getSingleInstance()
    {
        if(singleInstance == null) singleInstance = new RMAReceiver();
        return singleInstance;
    }

    @Override
    public void onReceive(Context context, Intent intent) 
    {
        System.out.println("Result Code: "+getResultCode());
//      resultCode = getResultCode();
        switch (getResultCode())
        {
            case Activity.RESULT_OK:
                msg = "SMS sent/delivered";
//              Toast.makeText(context, "SMS sent/delivered", 
//                      Toast.LENGTH_SHORT).show();
//              SMSService.sendSMS(context, "SMS sent/delivered", Global.confirmNo);
                break;
            case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                msg = "Generic failure";
//              Toast.makeText(context, "Generic failure", 
//                      Toast.LENGTH_SHORT).show();
//              SMSService.sendSMS(context, "Generic failure", Global.confirmNo);
                break;
            case SmsManager.RESULT_ERROR_NO_SERVICE:
                msg = "No service";
//              Toast.makeText(context, "No service", 
//                      Toast.LENGTH_SHORT).show();
//              SMSService.sendSMS(context, "No service", Global.confirmNo);
                break;
            case SmsManager.RESULT_ERROR_NULL_PDU:
                msg = "Null PDU";
//              Toast.makeText(context, "Null PDU", 
//                      Toast.LENGTH_SHORT).show();
//              SMSService.sendSMS(context, "No service", Global.confirmNo);
                break;
            case SmsManager.RESULT_ERROR_RADIO_OFF:
                msg = "Radio off";
//              Toast.makeText(context, "Radio off", 
//                      Toast.LENGTH_SHORT).show();
//              SMSService.sendSMS(context, "No service", Global.confirmNo);
                break;
            case Activity.RESULT_CANCELED:
                msg = "SMS not delivered";
//              Toast.makeText(context, "SMS not delivered", 
//                      Toast.LENGTH_SHORT).show();
//              SMSService.sendSMS(context, "No service", Global.confirmNo);
                break;
        }

        Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
        SMSService.sendSMS(context, msg, Global.confirmNo);



    }


}
  • 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-05-26T18:57:43+00:00Added an answer on May 26, 2026 at 6:57 pm

    It looks to me like you have set it up that way. Your IncomingSMSService calls your SMSService.sendSMS function which registers your SMSReceiver which sends an intent to start your IncomingSMSService all over again and so on.

    Try removing one link of this chain and see if it fixes your repetition problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an UITextView which takes data from XML. Now that XML node is
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
I want to add a search box for getting started example (Hello, World) on
I am getting following data <font color=\#ff0000\ face=\Verdana\ size=\5\>hello there</font><br/> I have 2 questions
Hello every one. I'm faced with a weird problem. My application has a simple
I have faced aweird problem with the following code, the code below suppose to
I'm new in web services. I have faced some problem. At the server side
Hello i have new Problem with Add Form my problem here WARNING: /test.xhtml @24,173
Hello again ladies and gents! OK, following on from my other question on ASP.NET
Hello I am working with a simulator that uses rcS scripts to boot, this

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.