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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:17:54+00:00 2026-06-07T01:17:54+00:00

I am new to android development.I am developing small android application. In my application

  • 0

I am new to android development.I am developing small android application. In my application I want to retrieve newly coming sms and display this message to user. My code looks like

// HellowordActivity.java
package com.example.helloword;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;

public class HellowordActivity extends BroadcastReceiver
{
    public void onReceive(Context context, Intent intent)
    {
    Bundle myBundle = intent.getExtras();
    SmsMessage [] messages = null;
    String strMessage = "";

    if (myBundle != null)
    {
        Object [] pdus = (Object[]) myBundle.get("pdus");
        messages = new SmsMessage[pdus.length];

        for (int i = 0; i < messages.length; i++)
        {
            messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
            strMessage += "SMS From: " + messages[i].getOriginatingAddress();
            strMessage += " : ";
            strMessage += messages[i].getMessageBody().toString();
            strMessage += "\n";
        }
         // Toast.makeText(context, strMessage, Toast.LENGTH_SHORT).show();

        Intent _intent = new Intent(context, PopupActivity.class);
        _intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        _intent.putExtra("strMessage", strMessage);
        startActivity(_intent);
       }
    }

  }  

I added receiver and permission in Android Manifest.xml

    <uses-permission android:name="android.permission.RECEIVE_SMS"/>

      <receiver android:name=".HellowordActivity" >
                <intent-filter > 
                <action android:name="android.provider.Telephony.SMS_RECEIVED"/> 
                </intent-filter> 
        </receiver> 
<activity android:name=".PopupActivity" android:launchMode="singleTop" />

I am not doing any thing in layout part.What I want as an output when new message will come;
message text display to user with simple popup.
Need Help.. Thank you…

  • 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-07T01:17:57+00:00Added an answer on June 7, 2026 at 1:17 am

    Try this it works for me you will get a toast shown to you with the content of the message received:

    package com.example.a;
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.telephony.SmsMessage;
    import android.util.Log;
    import android.widget.Toast;
    
        public class SMSBroadcastReceiver extends BroadcastReceiver {
    
                private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
                private static final String TAG = "SMSBroadcastReceiver";
    
                @Override
                public void onReceive(Context context, Intent intent) {
                     Log.i(TAG, "Intent recieved: " + intent.getAction());
    
                        if (intent.getAction().equals(SMS_RECEIVED)) {
                            Bundle bundle = intent.getExtras();
                            if (bundle != null) {
                                Object[] pdus = (Object[])bundle.get("pdus");
                                final SmsMessage[] messages = new SmsMessage[pdus.length];
                                for (int i = 0; i < pdus.length; i++) {
                                    messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
                                }
                                if (messages.length > -1) {
                                    Toast.makeText(context, "Message recieved: " + messages[0].getMessageBody(), 7000).show();
                                }
                            }
                        }
                   }
            }
    

    The AndroidManifest.xml

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.a"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="15" />
        <uses-permission android:name="android.permission.RECEIVE_SMS"/>
        <uses-permission android:name="android.permission.HARDWARE_TEST"/>
    
    
        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" >
            <receiver android:name=".SMSBroadcastReceiver" >
                <intent-filter>
                    <action android:name="android.provider.Telephony.SMS_RECEIVED" >
                    </action>
                </intent-filter>
            </receiver>
        </application>
    
    </manifest>
    

    Use DDMS to send sms to your emulator via Telnet

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

Sidebar

Related Questions

I'm new to android development. I'm developing an application for android 4.0.3 devices, in
I am new to java development, I am from C# .net, developing android application.
I want to start android tablet application development. i have created a new avd
I'm new to Android development. I have an application that allows the user to
Heloo everyone im new to android development and im developing an android application for
I am new to android development and am developing my first android application. I
i am new to android development and i am now developing a project. This
I'm developing an Android application. I'm very new on Android development. I see on
I'm developing an Android 3.1 application and I'm very very new on Android development.
I'm developing an Android 3.1 application. I'm very very new on Android development. I

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.