in my app i want to delete the sms's/calls of specific numbers i am new to android can any body help me
For calls: use content provider described here: http://d.android.com/reference/android/provider/CallLog.Calls.html
I'm not sure about SMS.
I use this to delete a particular message from the SMS inbox:
//Delete entire SMS thread.
getContext().getContentResolver().delete(
Uri.parse("content://sms/conversations/" + threadID),
null,
null);
//Delete single message.
getContext().getContentResolver().delete(
Uri.parse("content://sms/" + messageID),
null,
null);
These work for me given a valid Thread ID or Message ID.
Related
I am trying to create an sms conversation list. I am using this code to get a cursor:
Cursor cursor = activity.getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);
The problem is that when I use the cursor, I get multiple messages from one contact. I am trying to get only the most recent message from all contacts so that I can show them in a recyclerview as a list of conversations.
Thanks in advance!
Querying the "content://sms/conversations" URI (Telephony.Sms.Conversations.CONTENT_URI) will return a summary of each conversation, with the "snippet" column (Telephony.Sms.Conversations.SNIPPET) being the last message in each.
This query will also return with a "msg_count" column (Telephony.Sms.Conversations.MESSAGE_COUNT) - which is pretty self-explanatory - and a "thread_id" column (Telephony.Sms.Conversations.THREAD_ID), which can be used to retrieve a complete conversation, by querying with that ID appended to the conversations URI. For example:
String threadId = ...
Uri convoUri = Telephony.Sms.Conversations.CONTENT_URI
.buildUpon().appendPath(threadId).build();
Do note that these queries will return only SMS messages. If you want MMS as well, Telephony.Mms and Telephony.MmsSms have similar URIs.
I am trying to create an sms conversation list. I am using this code to get a cursor:
Cursor cursor = activity.getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);
The problem is that when I use the cursor, I get multiple messages from one contact. I am trying to get only the most recent message from all contacts so that I can show them in a recyclerview as a list of conversations.
Thanks in advance!
Querying the "content://sms/conversations" URI (Telephony.Sms.Conversations.CONTENT_URI) will return a summary of each conversation, with the "snippet" column (Telephony.Sms.Conversations.SNIPPET) being the last message in each.
This query will also return with a "msg_count" column (Telephony.Sms.Conversations.MESSAGE_COUNT) - which is pretty self-explanatory - and a "thread_id" column (Telephony.Sms.Conversations.THREAD_ID), which can be used to retrieve a complete conversation, by querying with that ID appended to the conversations URI. For example:
String threadId = ...
Uri convoUri = Telephony.Sms.Conversations.CONTENT_URI
.buildUpon().appendPath(threadId).build();
Do note that these queries will return only SMS messages. If you want MMS as well, Telephony.Mms and Telephony.MmsSms have similar URIs.
I want to read sms from my inbox. Here i want to read a specific message. Suppose mark has sent me a message i just want to make a query which will return the cursor indicating only Mark message .i have tried something like this but it is not working for me
Cursor cursor = contentResolverSender.query(
Uri.parse("content://sms/inbox"), null,"address =?"
,smsNo, null);
I wrote an sms sending application using the instructions Here. Now I want to add a suggestion for the phone number when the number or name is typed according to the number saved in the phone book i.e like when we enter number to call it suggests a number(dynamically on typing).
Is it possible to do or not? If possible then How Can I do this?I have used API level 2.2.
Edit:
I have do this with the help of Question Here But When I click on the name from phone-book,it place name on text-box but I have need the number to send sms.
Question: How could I get number so that I can sent message to the selected name.
Yes, it is possible. You can change fetch the existing numbers in your phone with ContactsContract, change your phone number EditText to an AutoCompleteTextView, and use a SimpleCursorAdapter to bind the numbers from your contacts to the AutoCompleteTextView.
Addition
If you want to convert a contact name into a phone number you can try this in your "Submit" Button's onClick() method:
Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER },
ContactsContract.Contacts.DISPLAY_NAME + " = '" + autoComplete.getText() + "'",
null, null);
if(cursor.moveToFirst())
phoneNo = cursor.getString(0);
Understand that this only gets the first number from the first contact that matches the name from your AutoCompleteTextView. You'll have to discern a way to distinguish between contacts with the same name and contact with multiple numbers.
I wanted to update the "message_count" column and "snippet" column of a sms conversation thread, using this content:"content://mms-sms/conversations". Because the snippet and message count is not updated when an SMS is deleted from the conversation thread.
But I got this error message: "MmsSmsProvider does not support deletes, inserts, or updates for this URI"
Below is my code:
ContentValues values = new ContentValues();
values.put("message_count", ent.getValue().getCount());
values.put("snippet", ent.getValue().getSnip());
Uri conUri = Uri.parse("content://mms-sms/conversations");
getContentResolver().update(conUri, values, null, null);
I also try like this:
Uri conUri = Uri.parse("content://mms-sms/conversations" + "/" + threadid);
getContentResolver().update(conUri, values, null, null);
But what I got is another error message:no such column: message_count: , while compiling: UPDATE pdu SET message_count=?,snippet=? WHERE thread_id=334
Thanks for any help
There is no way to update the count, snippet etc of a thread directly. But I can help you with your actual problem. There is actually a bug in the android code, which is the root of your issue. When you try to delete in the following way -
getContentResolver().delete("content://sms/", "_id=?", new String[] {id});
Android does not update the thread associated with that sms.
The solution is is to do this
getContentResolver().delete("content://sms/" + id, null, null);
For those who are curious what the bug is -
Android code does something stupid like this, when you delete using method 1 -
Delete all messages given by the query.
Get all the conversation threads associated with the messages given by the query and update them. Whoa wat ?! Step 1 just deleted messages given by query so, step 2 is always going to return a null set for threads associated with those message, as all the messages are already deleted.
Hope this helps.