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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:53:37+00:00 2026-05-24T17:53:37+00:00

I’m trying to intercept incoming SMS right after boot_completed but i’m having a problem

  • 0

I’m trying to intercept incoming SMS right after boot_completed but i’m having a problem with a NullPointerException in this line:

Object[] rawMsgs=(Object[])intent.getExtras().get("pdus");

Here’s my manifest:

    <uses-permission android:name="android.permission.SEND_SMS"></uses-permission> 
    <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission> 
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-    permission>
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar">
        <receiver android:name=".SMSReceiver" 
            android:permission="android.permission.BROADCAST_SMS"
            > 
            <intent-filter android:priority="1000"> 
                <action     android:name="android.provider.Telephony.SMS_RECEIVED"></action>
                <action android:name="android.intent.action.BOOT_COMPLETED"></action>
            </intent-filter> 
        </receiver>
    </application>

Receiver:

public class SMSReceiver extends BroadcastReceiver 
    { 


    private final LocationListener locationListener = new LocationListener() {
          public void onLocationChanged(Location location) {


          }

          public void onProviderDisabled(String provider){}
          public void onProviderEnabled(String provider) {}
          public void onStatusChanged(String provider, int status, Bundle extras) {} 
        };

    @Override
    public void onReceive(Context context, Intent intent) {


        LocationManager lm = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE); 
        //Get as fine grained location as possible, while saving battery life.
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        String provider = lm.getBestProvider(criteria, true);
        Toast toast3 = Toast.makeText(context, "Provider: "+provider, Toast.LENGTH_LONG);
        toast3.show();

        Object[] rawMsgs=(Object[])intent.getExtras().get("pdus");

        for (Object raw : rawMsgs) {
            SmsMessage msg=SmsMessage.createFromPdu((byte[])raw);
            SmsManager sms = SmsManager.getDefault();
            if (msg.getMessageBody().toUpperCase().contains("LOC")) {
                Log.w("SMS:"+msg.getOriginatingAddress(),
                            msg.getMessageBody());
                Toast toast1 = Toast.makeText(context, "Phone Number: "+msg.getOriginatingAddress()+" Message: "+msg.getMessageBody(), Toast.LENGTH_LONG);
                toast1.show();
                abortBroadcast();

                if(provider!=null){


                    lm.requestLocationUpdates(provider, 0, 0, locationListener);

                    if(lm != null)
                    {

                        Location last_good = lm.getLastKnownLocation(provider);
                        if(last_good != null)
                        {
                            Toast.makeText(context, "Got Message from " + msg.getOriginatingAddress() + " , Sending" + last_good.toString(),     Toast.LENGTH_SHORT).show();
                            //sendSMS(msg.getOriginatingAddress(), "http://maps.google.com?q=" + last_good.convert(last_good.getLatitude(), Location.FORMAT_DEGREES) + "," + last_good.convert(last_good.getLongitude(), Location.FORMAT_DEGREES), context);

                            //sendSMS(msg.getOriginatingAddress(), last_good.getLatitude() + "," + last_good.getLongitude(), context);
                            sms.sendTextMessage(msg.getOriginatingAddress(), null, last_good.getLatitude() + "," + last_good.getLongitude(), null, null); 
                            lm.removeUpdates(locationListener);
                        }
                        else
                        {
                            lm.removeUpdates(locationListener);
                                sendSMS(msg.getOriginatingAddress(),"Location Not Available. Possible Reasons: Phone is Off, GPS is Off, No Satellites in sight", context);

                        }
                    }

                }
                else{
                    sendSMS(msg.getOriginatingAddress(),"Location Not Available. Possible Reasons: Phone is Off, GPS is Off, No Satellites in sight", context);

                }



            }
        }
     }

Thanks.

  • 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-24T17:53:39+00:00Added an answer on May 24, 2026 at 5:53 pm

    The problem here is that your BroadcastReceiver implementation has been mapped to two intents – android.provider.Telephony.SMS_RECEIVED and android.intent.action.BOOT_COMPLETED – but in the onReceive implementation you’re not checking which intent you are processing.

    My guess is that android.intent.action.BOOT_COMPLETED has been received and intent.getExtras() is returning null. You could confirm this by adding some logging to the method and watching the logcat window (if you’re using Eclipse).

    If you write a service or broadcast receiver and map it to multiple intents it is good practice – nay essential – to check which intent has been received and process it appropriately. Personally I’d go for something like this:

    if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
        // boot-related processing here
    }
    else if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
        // SMS-related processing here
    }
    else {
        // intent not handled - log as a warning as you've registered to receive it
    }
    

    You can’t assume fail-safe behaviour. For clarity, move the intent processing logic into a separate method:

    if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
        processBootCompletedIntent(intent);
    }
    else if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
        processSmsReceivedIntent(intent);
    }
    else {
        // intent not handled - log as a warning as you've registered to receive it
    }
    

    PS – most (if not all) ‘native’ intent action strings are held as constants in a relevant class. For example android.intent.action.BOOT_COMPLETED is defined as Intent.ACTION_BOOT_COMPLETED. Use the constants where they exist, it’ll save you making any typing errors.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

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.