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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:28:33+00:00 2026-05-28T06:28:33+00:00

I know that there are a few Questions here on SO relating to this,

  • 0

I know that there are a few Questions here on SO relating to this, but none of them helped me to get this working – capture SMS that being sent.
I am using Android 2.2 (FROYO) on a Samsung phone (if that matters somehow).

I’ve searched a lot for this on Stackoverflow and realized that I need ContentObserver for my request. I’m using Service instead of Activity, so I’ve registered that ContentObserver in my Service class, and it looks like this:

public class SMSSending extends Service {

private class MyContentObserver extends ContentObserver {

    public MyContentObserver() {
        super(null);
    }

    @Override
    public void onChange(boolean selfChange) {
        super.onChange(selfChange);      

        Uri uriSMSURI = Uri.parse("content://sms/sent");
        Cursor cur = getBaseContext().getContentResolver().query(uriSMSURI, null, null, null, null);           
        cur.moveToNext();
        String content = cur.getString(cur.getColumnIndex("body"));

        Toast.makeText(getApplicationContext(), "SOME TEXT", Toast.LENGTH_LONG).show();

    }

    @Override
    public boolean deliverSelfNotifications() {
        return false;
    }
}

@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onCreate() {

    MyContentObserver contentObserver = new MyContentObserver();
    ContentResolver contentResolver = getBaseContext().getContentResolver();
    contentResolver.registerContentObserver(Uri.parse("content://sms/sent"),true, contentObserver);
    Toast.makeText(getApplicationContext(), "SERVICE CREATED", Toast.LENGTH_LONG).show();
}


@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    return START_STICKY;
}

@Override
public void onStart(Intent intent, int startid) {
    Toast.makeText(getApplicationContext(), "SERVICE STARTED", Toast.LENGTH_LONG).show();
}

}

As you can see I’ve put Toast in few places so I could see if this is working at all – and unfortunately none of this notifications appear. Also, i tried with putting some code for LogCat but nothing happens.
I’ve also tried to put Uri uriSMSURI = Uri.parse("content://sms"); instead of content://sms/sent
but the application simply doesn’t do anything.
Of course, I have permissions in Manifest:

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

What am i missing?

  • 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-28T06:28:33+00:00Added an answer on May 28, 2026 at 6:28 am

    Fortunately, I’ve managed to work it out, but by using totally different approach. Maybe is this going to help someone in future..

    Instead of using ContentObserver (which I still don’t know why didn’t work) I’ve created new Thread and started it after my service has been created and started. So it looks like this:

    ...
    
    final Uri CONTENT_URI = Uri.parse("content://sms/sent"); 
    
    ...
    
     public void onStart(Intent intent, int startid) { 
            Go();   
        }
        private void Go(){
    
            new Thread(new Runnable() { 
                public void run() { 
    
                    try {       
    
                    while(true){
    
                    Cursor cursor = getContentResolver().query(CONTENT_URI, null, null, null,  null); 
    
                    if(cursor.moveToFirst()){
    
                        text = cursor.getString(cursor.getColumnIndexOrThrow("body")).toString(); 
    
    
                        if(!text.equalsIgnoreCase(actual)){
                            previous = text;
                                        //do what you need..
    
    
                        }
    
                    }
    
                    Thread.sleep(60000);
                }
    
                } catch (InterruptedException e) {
    
                    e.printStackTrace();
                }   
                } 
        }).start(); 
    

    It’s working absolutely stable, even better than with using ContentObserver, having in mind that lot of people had problems with it, something like this and some other..

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

Sidebar

Related Questions

I know that there are a few questions like this on SOF, but I
I know there are a few questions floating around here on the subject, but
I know there are a few similar questions to this but I just can't
There were few questions related to this but none answered the question in my
I know that there are a few similar questions and I googled a lot
I know that there are lots of examples out there on this, but they
I know that there are many Delphi database related questions available, but I'm considering
there are already a few questions relating to this problem. I think my question
I know there are plenty of questions here already about this topic (I've read
I know there are few questions regarding this issue of 'getView called few times'

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.