PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 13, 2022

[FIXED] How to delete Multiple messages or single message from the Inbox in Android?

 July 13, 2022     android, android-contentresolver, message     No comments   

Issue

I access all Message from the Inbox with the help of Content Resolver But Now the problem is that I want to delete Multiple Message Or a single Message from the Inbox. I have found delete functionality for all messages not for a single message or multiple message. I store all message in a ArrayList. Any Help will be appreciated.

My code for read Message is:--

Uri uriSMSURI = Uri.parse("content://sms/inbox");
Cursor cur = getContentResolver().query(uriSMSURI , null, null, null,
                null);
        startManagingCursor(cur);

        int size=cur.getCount();


        if (cur.moveToFirst()) 
        {

            for(int i=0;i<size;i++)
            {
                    InboxField tempInboxField = new InboxField();
                    tempInboxField.body = cur.getString(cur.getColumnIndexOrThrow("body"));
                    tempInboxField.protocol = cur.getString(cur.getColumnIndexOrThrow("protocol"));
                    tempInboxField.type =cur.getString(cur.getColumnIndexOrThrow("type"));
                    tempInboxField.status = cur.getInt(cur.getColumnIndexOrThrow("status"));
                    tempInboxField.address =cur.getString(cur.getColumnIndexOrThrow("address"));
                    String tempdate =cur.getString(cur.getColumnIndexOrThrow("date"));
                    tempInboxField.id = cur.getInt(cur.getColumnIndexOrThrow("_id"));
                    tempInboxField.person = cur.getString(cur.getColumnIndexOrThrow("person"));
                    Long timestamp = Long.parseLong(tempdate);    
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTimeInMillis(timestamp);
                    Date finaldate = calendar.getTime();
                    tempInboxField.date = finaldate.toString();
                    arrayList.add(tempInboxField);
                    cur.moveToNext();
                }

            }

Solution

You can delete a single message using this:

Uri deleteUri = Uri.parse("content://sms");
int count = 0;
Cursor c = context.getContentResolver().query(deleteUri, null, null,
        null, null);
while (c.moveToNext()) {
   try {
   // Delete the SMS
   String pid = c.getString(0); // Get id;
   String uri = "content://sms/" + pid;
   count = context.getContentResolver().delete(Uri.parse(uri),
               null, null);
   } catch (Exception e) {

   }
}

If you want to delete a conversation thread you can use something like this:

String uri = "content://sms/conversations/" + pid;
getContentResolver().delete(Uri.parse(uri), null, null);  

where pid is the id of the thread.



Answered By - frayab
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing