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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:24:58+00:00 2026-06-04T14:24:58+00:00

I have been developing the application which can manage a device using SMS commands;

  • 0

I have been developing the application which can manage a device using SMS commands; the application must execute commands from SMS and delete this Sms. So, the code for managing works, but I can’t delete the SMS. I have following BroadcastReceiver:

public class SmsReceiver extends BroadcastReceiver {

    private static final Uri SMS_INBOX_URI = Uri.parse("content://sms");

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        String body = "";
        String number = "";

        Bundle bundle = intent.getExtras();
        SmsMessage[] msgs = null;
        if (bundle != null) {
            // ---retrieve the SMS message received---
            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]);
                body += msgs[i].getMessageBody().toString();
                number +=msgs[i].getOriginatingAddress();
            }
        }

        SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(context);
        String key=prefs.getString(context.getString(R.string.acc_key_key), "");

        if (body.trim().equals("#"+key)) {
            sendGPSCoordinates(context, number);
        } else if (body.trim().equals("?"+key)){
            sendResponces(context);
        }
        deleteSms(body, number, context);
    }

    private void deleteSms(String body, String number, Context context) {

        ContentResolver resolver=context.getContentResolver();
        int count=resolver.delete(SMS_INBOX_URI, "body = ? AND address = ?", new String[]{body, number});
        Log.e("count", String.valueOf(count));
/*      Cursor results=resolver.query(SMS_INBOX_URI, null, null, null, null);
        for (String str:results.getColumnNames()) {
            Log.e("column", str);
        }
}

and I have AndroidManifest.xml with needed permissions. The application receives the SMS, gets the SMS data from an Intent, manage the phone and tries to delete this SMS, but it always returns count is equals 0. I have tried to change URI for sms/inbox, but it doesn’t works. Please, tell me, how can I do it? 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-04T14:24:59+00:00Added an answer on June 4, 2026 at 2:24 pm

    I assume, that you know, that an SMS-Message is send as ordered-Broadcast. So your Reciever has the ability to get them BEFORE the native SMS-app will get it (just set a higher priority inside Manifest than the native one). Therefore it should work to just cancel the Broadcast being send, that the SMS never reaches the native sms-app.

    You could try it like this:

    public class SmsReceiver extends BroadcastReceiver {
    
    private static final Uri SMS_INBOX_URI = Uri.parse("content://sms");
    
    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        String body = "";
        String number = "";
    
        Bundle bundle = intent.getExtras();
        SmsMessage[] msgs = null;
        if (bundle != null) {
            // ---retrieve the SMS message received---
            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]);
                body += msgs[i].getMessageBody().toString();
                number +=msgs[i].getOriginatingAddress();
            }
        }
    
        SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(context);
        String key=prefs.getString(context.getString(R.string.acc_key_key), "");
    
        if (body.trim().equals("#"+key)) {
            sendGPSCoordinates(context, number);
        } else if (body.trim().equals("?"+key)){
            sendResponces(context);
        }
        abortBroadcast();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been developing the application which must recognize SMS commands. So, I need
I have been developing the application which must catch all input sms. For it
I have been developing an application which needs to download a file from the
I have been developing Android application which has 3 ListView and one ContextMenu for
I have a project (Web Application) which I have been developing in C#/ASP.NET, and
Ok, I have been thinking of developing a web application using the play framework
I have been developing a plain JSP/Servlet web application, which focuses mainly in collecting
I have been developing an iPad application in which I want to implement multithreading,
I have been developing Android application for Android 3.x and now I want to
I have been developing a sample application after reading Rails 3 Tutorial book. In

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.