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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:02:29+00:00 2026-05-30T12:02:29+00:00

I already asked a question here : combining-2-extended-activity-for-sms-notification And now i get a new

  • 0

I already asked a question here :
combining-2-extended-activity-for-sms-notification

And now i get a new problem 😀

So i already make a nested Class like this :

public class SMSNotif extends Activity{
static final int HELLO_ID = 1;
BroadcastReceiver myReceiver = null;

public class SMSReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context arg0, Intent arg1) {
        // TODO Auto-generated method stub

        Bundle bundle = arg1.getExtras();
        SmsMessage[] 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";
            }

            Toast.makeText(arg0, str, Toast.LENGTH_SHORT).show();
        }
        //Intent i = new Intent(SMSReceiver.this, SMSNotif.class);
    }
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    //String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    //int icon = R.drawable.ic_launcher;
    String tickerText = "Hello";
    //long when = System.currentTimeMillis();

    Notification notification = new Notification(R.drawable.ic_launcher, tickerText, System.currentTimeMillis());

    //Context context = getApplicationContext();
    String contentTitle = "My notification";
    String contentText = "Hello World!";
    Intent notificationIntent = new Intent(this, SMSNotif.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);
    notification.defaults = Notification.DEFAULT_ALL;
    mNotificationManager.notify(HELLO_ID, notification);

}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    if(myReceiver != null){
        unregisterReceiver(myReceiver);
        myReceiver = null;
    }
    super.onPause();
}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();

    if(myReceiver == null){
        myReceiver = new SMSReceiver();
        IntentFilter filter = new IntentFilter();
        registerReceiver(myReceiver, filter);
    }
}

}

And my MANIFEST is like this :

 <activity
        android:name=".SMSNotif"
        android:label="@string/app_name" >
         <receiver android:name=".SMSReceiver" >
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>
    </activity>

The problem is, my app can’t detect any new SMS now…
Where is my mistake?is it in my manifest?
I already tried changing my codes but i still can’t solve my problem…
So the question is :
Can you help me so my app can detect new SMS and make a notification everytime new SMS comes?
Thank you very much! 😀
And sory if i made some mistakes, English is not my native languange 🙂
I have an Idea : I tried to reverse the Class, so SMSReceiver will be the outer one and SMSNotif will be inside it…is it possible?(i tried it, and i got some errors) I think by inverse it the BroadcastReceiver will be able to detect new SMS..is it true?

  • 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-30T12:02:31+00:00Added an answer on May 30, 2026 at 12:02 pm

    You should specify that your receiver is in inner class in manifest.

         <activity
                android:name=".SMSNotif"
                android:label="@string/app_name" >
    
            </activity>
    
     <receiver android:name="your.package.name.SMSNotif$SMSReceiver" >
                <intent-filter>
                    <action android:name="android.provider.Telephony.SMS_RECEIVED" />
                </intent-filter>
            </receiver>
    

    The Receiver should not be in activity.

    and your inner class SMSReceiver should be static

    EDITED
    If you want to just show the notification then Activity is not Required.

    public class SMSReceiver extends BroadcastReceiver {
    
        private static final int HELLO_ID = 0;
    
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            // TODO Auto-generated method stub
    
            Bundle bundle = arg1.getExtras();
            SmsMessage[] 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";
                }
    
                Toast.makeText(arg0, str, Toast.LENGTH_SHORT).show();
    
                // String ns = Context.NOTIFICATION_SERVICE;
                NotificationManager mNotificationManager = (NotificationManager) arg0
                        .getSystemService(Context.NOTIFICATION_SERVICE);
    
                // int icon = R.drawable.ic_launcher;
                String tickerText = "Hello";
                // long when = System.currentTimeMillis();
    
                Notification notification = new Notification(
                        R.drawable.ic_launcher, tickerText,
                        System.currentTimeMillis());
    
                // Context context = getApplicationContext();
                String contentTitle = "My notification";
                String contentText = "Hello World!";
                Intent notificationIntent = new Intent(arg0, SMSNotif.class);
                PendingIntent contentIntent = PendingIntent.getActivity(arg0, 0,
                        notificationIntent, 0);
    
                notification.setLatestEventInfo(arg0, contentTitle, contentText,
                        contentIntent);
                notification.defaults = Notification.DEFAULT_ALL;
                mNotificationManager.notify(HELLO_ID, notification);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my problem. I already asked that question in the XAMPP community forum
I already asked similar question here, but I still get some errors, so I
Searching here I found that this question was already asked , but I think
I already asked the same question over at dev.twitter.com , however, I didn't get
I'm asking the same question here that I've already asked on msdn forums http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/70f40a4c-8399-4629-9bfc-146524334daf
i know i asked already the question about the ping script but now i
This kind of builds up on Already asked question ... However here, say, I'm
After searching for a solution I decided to re-ask a question already asked here
I already asked same question here after that i came up with this code
I've already asked this question, but I think I din't explain the problem well

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.