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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:54:26+00:00 2026-06-12T12:54:26+00:00

i have the following code which gives a receiver not registered through an illegal

  • 0

i have the following code which gives a receiver not registered through an illegal argument exception

public class CheckServer extends IntentService
{

public String snumber;

public CheckServer()
{
  super("CheckServer");
}


@Override
public void onCreate()
{
  super.onCreate();

  String DELIVERED = "SMS_DELIVERED";

  DeliveryReceiver dReceiver = new DeliveryReceiver();

  registerReceiver(dReceiver,new IntentFilter(DELIVERED));

}

@Override
public void onDestroy()
{
  super.onDestroy();

  DeliveryReceiver dReceiver = new DeliveryReceiver();

  unregisterReceiver(dReceiver);
  dReceiver = null;
}


@Override
protected void onHandleIntent(Intent intent)
{
  try
  {
    serviceAction();
  }
  catch (ClientProtocolException e)
  {
    e.printStackTrace();
  }
  catch (IOException e)
  {
    e.printStackTrace();
  }
  catch (URISyntaxException e)
  {
    e.printStackTrace();
  }
  catch (JSONException e)
  {
    e.printStackTrace();
  }

  scheduleNextUpdate();
}

private void scheduleNextUpdate()
{
  Intent intent = new Intent(this, this.getClass());
  PendingIntent pendingIntent =
    PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

  long currentTimeMillis = System.currentTimeMillis();
  long nextUpdateTimeMillis = currentTimeMillis + 1 * DateUtils.MINUTE_IN_MILLIS;
  Time nextUpdateTime = new Time();
  nextUpdateTime.set(nextUpdateTimeMillis);

  AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
  alarmManager.set(AlarmManager.RTC, nextUpdateTimeMillis, pendingIntent);
}

public void serviceAction() throws ClientProtocolException, IOException, URISyntaxException, JSONException
{
  HttpResponse response = null;
  HttpClient client = new DefaultHttpClient();
      HttpGet request = new HttpGet();
      request.setURI(new URI("http://www.examplecom/sms/getsms"));
      response = client.execute(request);

      String result = convertStreamToString(response.getEntity().getContent());

      String no,message;

      JSONArray array = new JSONArray(result);

      for (int i = 0; i < array.length(); i++)
      {
        JSONObject row = array.getJSONObject(i);
        snumber = row.getString("sno");
        no = row.getString("no");
        message = row.getString("message");
        sendSMS(no , message);
      }
}

public static String convertStreamToString(InputStream inputStream) throws IOException
{
  if (inputStream != null)
  {
      Writer writer = new StringWriter();

      char[] buffer = new char[1024];
      try
      {
          Reader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"),1024);
          int n;
          while ((n = reader.read(buffer)) != -1)
          {
              writer.write(buffer, 0, n);
          }
      }
      finally
      {
          inputStream.close();
      }
      return writer.toString();
  }
  else
  {
      return "";
  }
}

public void sendSMS(String number,String message)
{
  String DELIVERED = "SMS_DELIVERED";

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

  SmsManager smsM = SmsManager.getDefault();
  smsM.sendTextMessage(number, null, message, null, deliveredPI);
}

public class DeliveryReceiver extends BroadcastReceiver
{     
  @Override
   public void onReceive(Context context, Intent arg1)
  {
               switch (getResultCode())
               {
                   case Activity.RESULT_OK:

                       Toast.makeText(getBaseContext(), "SMS delivered",Toast.LENGTH_SHORT).show();
                        try
                        {
                                updateSMSstatus(snumber);
                        }
                        catch (ClientProtocolException e)
                        {
                                e.printStackTrace();
                        }
                        catch (URISyntaxException e)
                        {
                                    e.printStackTrace();
                        }
                        catch (IOException e)
                        {
                                            e.printStackTrace();
                        }

                       break;

                   case Activity.RESULT_CANCELED:

                       Toast.makeText(getBaseContext(), "SMS not delivered",Toast.LENGTH_SHORT).show();

                       break;                        
               }

  }

  public void updateSMSstatus(String sno) throws URISyntaxException, ClientProtocolException, IOException
  {
      HttpResponse response = null;
      HttpClient client = new DefaultHttpClient();
      HttpGet request = new HttpGet();
      request.setURI(new URI("http://www.example.com/sms/updatesmsstatus?uname=someone&sno="+sno));
      response = client.execute(request);


  }
}

the problem is that i get a register not received error even though i register it in the onCreate() method, what might be the problem?

  • 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-12T12:54:28+00:00Added an answer on June 12, 2026 at 12:54 pm

    Instead of registering in onCreate() and unregistering in onDestroy() methods, I changed the sendSMS method to following:

    public void sendSMS(String number,String message,String serialnum) 
    {  
      String DELIVERED = "SMS_DELIVERED";
    
      Intent delivered = new Intent(DELIVERED);
      delivered.putExtra("MsgNum", serialnum);
      PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, delivered, 0);
    
        registerReceiver(
            new BroadcastReceiver() 
            {   
                @Override
               public void onReceive(Context context, Intent intent)
               {
                           switch (getResultCode())
                           {
                               case Activity.RESULT_OK:
    
                                   Toast.makeText(getBaseContext(), "SMS delivered",Toast.LENGTH_SHORT).show();
    
                                   updateSMSStatus USS =  new updateSMSStatus();
    
                                   USS.execute(intent.getStringExtra("Msgnum"));
    
                                   break;
    
                               case Activity.RESULT_CANCELED:
    
                                   Toast.makeText(getBaseContext(), "SMS not delivered",Toast.LENGTH_SHORT).show();
    
                                   break;                        
                           }
    
                         unregisterReceiver(this);
                }
    
            },
            new IntentFilter(DELIVERED)); 
    
        SmsManager smsMngr = SmsManager.getDefault();
        smsMngr.sendTextMessage(number, null, message, null, deliveredPI);
    
    }
    

    The sms delivered action is now triggered, thanks all.

    Any ideas on how to differentiate the delivery reports of each sms?

    I’m not pretty sure on how to use the intent.putExtra() method in my service with the delivery BroadcastReceiver.

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

Sidebar

Related Questions

I have the following piece of code: class Student { public: Student(){} void display()
I have the following code which gives me an error. I want to add
I have a following code which works fine MsgBox(AddSomething(Of String)(Hello, World)) Public Function AddSomething(Of
I have the following code which is fine if I give invalid parameters (though,
I have following code which works for radio buttons but need to be changed
I want to know is below code correct ? I have following code which
I have the following code which definitely returns a proper data result if I
I have the following code which is working, I was wondering if this can
I have the following code which is used to upload large files (~6MB) to
i have the following code which switches some fullscreen-background-images (fadeOut, fadeIn). setInterval(function() { var

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.