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

  • Home
  • SEARCH
  • 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 8672273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:09:45+00:00 2026-06-12T19:09:45+00:00

I am trying to delete sms. String URI = content://sms/inbox; Cursor cursor = getContentResolver().query(Uri.parse(URI),

  • 0

I am trying to delete sms.

String URI = "content://sms/inbox";
Cursor cursor = getContentResolver().query(Uri.parse(URI), null,null, null, null);
String[] _id = new String[cursor.getCount()];
String[] thread_id = new String[cursor.getCount()];
if (cursor.moveToFirst()) {
    for (int i = 0; i < cursor.getCount(); i++) {
        try {
            _id[i] = cursor.getString(cursor.getColumnIndexOrThrow("_id")).toString();
            thread_id[i] = cursor.getString(cursor.getColumnIndexOrThrow("thread_id")).toString();
        } catch (IllegalArgumentException e) {
            Log.d(TAG, e.toString());
        }
    }
}
final String id = _id[0]; // for debugging deleting the first msg
final String tid = thread_id[0]; // for debugging deleting the first msg
((Button) findViewById(R.id.delete)).setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
            Log.d(TAG, "id="+id+",tid="+tid);
            getContentResolver().delete(Uri.parse(URI),"_id=" + id + " and thread_id=" + tid,new String[] { String.valueOf(id),String.valueOf(tid) });
            Toast.makeText(getApplicationContext(), "SMS DELETED. RESTARTING ACTIVITY", Toast.LENGTH_LONG);
            Intent i = getApplicationContext().getPackageManager().getLaunchIntentForPackage(getApplicationContext().getPackageName());
            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(i);
    }
});

It throws an exception:

10-06 00:48:43.234: E/AndroidRuntime(27912): FATAL EXCEPTION: main
10-06 00:48:43.234: E/AndroidRuntime(27912): java.lang.IllegalArgumentException: Unknown URL
10-06 00:48:43.234: E/AndroidRuntime(27912):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:144)
10-06 00:48:43.234: E/AndroidRuntime(27912):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
10-06 00:48:43.234: E/AndroidRuntime(27912):    at android.content.ContentProviderProxy.delete(ContentProviderNative.java:483)
10-06 00:48:43.234: E/AndroidRuntime(27912):    at android.content.ContentResolver.delete(ContentResolver.java:675)
10-06 00:48:43.234: E/AndroidRuntime(27912):    at com.example.detector.MainActivity$1.onClick(MainActivity.java:85)
10-06 00:48:43.234: E/AndroidRuntime(27912):    at android.view.View.performClick(View.java:2408)
10-06 00:48:43.234: E/AndroidRuntime(27912):    at android.view.View$PerformClick.run(View.java:8816)
10-06 00:48:43.234: E/AndroidRuntime(27912):    at android.os.Handler.handleCallback(Handler.java:587)
10-06 00:48:43.234: E/AndroidRuntime(27912):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-06 00:48:43.234: E/AndroidRuntime(27912):    at android.os.Looper.loop(Looper.java:123)
10-06 00:48:43.234: E/AndroidRuntime(27912):    at android.app.ActivityThread.main(ActivityThread.java:4633)
10-06 00:48:43.234: E/AndroidRuntime(27912):    at java.lang.reflect.Method.invokeNative(Native Method)
10-06 00:48:43.234: E/AndroidRuntime(27912):    at java.lang.reflect.Method.invoke(Method.java:521)
10-06 00:48:43.234: E/AndroidRuntime(27912):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
10-06 00:48:43.234: E/AndroidRuntime(27912):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
10-06 00:48:43.234: E/AndroidRuntime(27912):    at dalvik.system.NativeStart.main(Native Method)

The exception is thrown while deleting the deletion. I have following in my manifest:

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

I tried changing the URL to content://sms for delete. Did not work. Gives following exception:

10-06 01:59:57.602: E/AndroidRuntime(29381): android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x6cfa38
10-06 01:59:57.602: E/AndroidRuntime(29381):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:158)
10-06 01:59:57.602: E/AndroidRuntime(29381):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
10-06 01:59:57.602: E/AndroidRuntime(29381):    at android.content.ContentProviderProxy.delete(ContentProviderNative.java:483)
10-06 01:59:57.602: E/AndroidRuntime(29381):    at android.content.ContentResolver.delete(ContentResolver.java:675)
10-06 01:59:57.602: E/AndroidRuntime(29381):    at com.example.detector.MainActivity$1.onClick(MainActivity.java:85)

Can some body look at this and tell what the problem is?

  • 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-12T19:09:47+00:00Added an answer on June 12, 2026 at 7:09 pm

    I think what you actually need is:

    getContentResolver().delete(Uri.parse(URI),"_id=? and thread_id=?",new String[] { String.valueOf(id),String.valueOf(tid) });
    

    It looks like delete() uses prepared statements, which means that you wouldn’t be passing ids in the statement string since they are passed in the third argument.

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

Sidebar

Related Questions

I'm trying to delete some triples using this query: deleteQuery = DELETE { ?a
I am currently trying to delete a SMS from the SMS table from android.
I am trying to implement SMS kind of swipe and delete functionality. In case
Hi I am trying to delete an HTML tag from a string. The tag
I am trying to delete some triples using a SPARQL query. delete ?s ?p
I trying to delete an appointment in an public calendar. ExchangeService Exchange = new
Am trying to delete a word from a string in my database The string
I'm trying delete a class body in using the new Text Editor code model
I am trying to delete a sub-column of a super column family. I tried
I am trying to delete a cookie with this function , but it doesnt

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.