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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:45:22+00:00 2026-05-29T21:45:22+00:00

i am doing an sms hiding project which is broadcast receiver the code is

  • 0

i am doing an sms hiding project which is broadcast receiver
the code is given below

package com.sms.sms;



public class ReceiverClass extends BroadcastReceiver 
{

SQLiteDatabase DiaryDB = null;
String message,number;
@Override
public void onReceive(Context context, Intent intent)
{



    Bundle bundle = intent.getExtras();
    SmsMessage[ ] msgs = null;
    String str = "";
    if (bundle != null)
    {
        abortBroadcast();
        //---retrieve the received message here ---
        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";
            message = msgs[i].getMessageBody().toString();
            number = msgs[i].getOriginatingAddress();
        }
       // ........first show sms here.....
       Toast.makeText(context, str, Toast.LENGTH_SHORT).show(); 

       String name = findNameByAddress(context, number);
       if(name.equals(number))
           name = "Unknown";           

       DiaryDB = context.openOrCreateDatabase("DIARY_DATABASE", context.MODE_PRIVATE, null);

       DiaryDB.execSQL("CREATE TABLE IF NOT EXISTS Messages (TIMESTAMP DATE DEFAULT (DATETIME('now','localtime')), MESSAGE varchar, SENDER varchar, NAME varchar);");
System.out.println("table createdddddddddddddddddddddddddd");

       DiaryDB.execSQL("INSERT INTO Messages(MESSAGE,SENDER,NAME) VALUES('" + message +"','"+ number +"','"+ name +"')");

       DiaryDB.close();
       updateName(context,name, number);

   }



}  
 public String findNameByAddress(Context ct,String address)
    {
         Uri myPerson = Uri.withAppendedPath(ContactsContract.CommonDataKinds.Phone.CONTENT_FILTER_URI, Uri.encode(address));

         String[] projection = new String[] { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME };

         Cursor cursor = ct.getContentResolver().query(myPerson, projection, null, null, null);

         if (cursor.moveToFirst())
         {

             String name=cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));

             Log.e("","Found contact name");

             cursor.close();

             return name;

         }

         cursor.close();
         Log.e("","Not Found contact name");

         return address;
    }

 public void updateName(Context ct, String name, String sender)
 {
     DiaryDB = ct.openOrCreateDatabase("DIARY_DATABASE", ct.MODE_PRIVATE, null);

     DiaryDB.execSQL("UPDATE Messages SET NAME='"+name+"' WHERE SENDER='"+sender+"'");

     DiaryDB.close();
 }

I had two button ON and OFF in my main Activity. What I need is that when i press the ON button it should Start the Bordcast receiver and should start hide sms and when i press the OFF button i need to stop (Broadcast receiver)hiding messages process or should get sms back to the inbox*(which will occur when the broadcast receiver get turned off)*. now how can i on and off a Boardcast receiver process please help

edition after answer

my activity class//

package com.an.oid;



public class OnoffActivity extends Activity {
int count =0;
Button a,b;
 ReceiverClass rc ;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    a=(Button)findViewById(R.id.button1);
    b=(Button)findViewById(R.id.button2);

    rc= new ReceiverClass();
    a.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
             IntentFilter filter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
             System.out.println("onnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn");



               registerReceiver(rc,filter);


        }
    });
    b.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub

             unregisterReceiver(rc);
        }
    });
}
}

my manifest//

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.an.oid"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:label="@string/app_name"
        android:name=".OnoffActivity" >
        <intent-filter >
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
 <uses-permission android:name="android.permission.SEND_SMS">
</uses-permission>
<uses-permission android:name="android.permission.READ_SMS" />



</manifest>

After getting anser i tried this but it is not working?

  • 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-29T21:45:24+00:00Added an answer on May 29, 2026 at 9:45 pm

    This is only possible if you register your receiver at Activity level(not Manifest) using

    registerReceiver(BroadcastReceiver, IntentFilter)
    

    and on the click of the button you can Unregister it using..

    unregisterReceiver(BroadcastReceiver receiver)
    

    Edit II

    //register button

    register.setOnClickListener(new OnClickListener() {
    
            public void onClick(View v) {
    
               IntentFilter filter = new IntentFilter(MY_ACTIVITY);
               Sms2Activity rc = new Sms2Activity();
               registerReceiver(rc,filter);
    
    }
        });
    

    //Unregister button

     unregister.setOnClickListener(new OnClickListener() {
    
                public void onClick(View v) {
    
                  unregisterReceiver(rc);
    
        }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently noticed the following code which basically defines a class method public Func<string,
Doing the below will reproduce my problem: New WPF Project Add ListView Name the
I am doing the following code in order to listen for incoming SMS's and
Doing an ajax get request works as expected using the following code: $.ajax({ type:
When doing TDD , how to tell that's enough tests for this class /
I have created a class library (assembly) that provides messaging, email and sms. This
I'm doing a desktop academic project one of the requirment of this project is
I am doing sample application using windows mobile 5.0. When I receive an SMS,
I have this code to send an SMS message with an attachment that is
i am building this sms notification system, which will send 10 times free sms

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.