I am looking for code to get the total sent-sms count in android mobiles. If I use content://sms/sent/ for querying the database I get the sms count of the available sent sms in the mobile, but I want the total sms that is sent from buying the mobile.
Retrieve All SMS messages in the Android
The URI (content://sms/) will used to retrive the all SMS messages, also we can split up by the message type as well as.
Uri allMessage = Uri.parse("content://sms/");
ContentResolver cr = getContentResolver();
Cursor c = cr.query(allMessage, null, null, null, null);
while (c.moveToNext()) {
String row = c.getString(1);
}
you can get the all inbox/outbox here
change your URI
use this one: content://sms/
Related
I want to detect from sms list, which of messages are mine and witch of them belongs to other contacts.
For example:
Me: "body": Hi John
John "body: Hi there...
Uri uriSMSURI = Uri.parse("content://sms/");
Cursor cur = getActivity().getContentResolver().query(uriSMSURI, null, null, null, null);
while (cur.moveToNext()) {
//detect here
}
You can use the Telephony.TextBasedSmsColumns.CREATOR field to get the creator. Compare this to your address (mobile number) to distinguish yourself from the other people. You can get your number with the following:
(TelephonyManager)getSystemService(TELEPHONY_SERVICE).getLine1Number();
I am implementing sms application, I want to store all sms values into internal xml file and restore sms values from xml file into sms application, so far inbox messages and sent messages working fine but problem with draft messages.
please help me on this , thank you.
// Create Draft box URI
Uri draftURI = Uri.parse("content://sms/draft");
// List required columns
String[] reqCols = new String[] { "_id", "address", "body" };
// Get Content Resolver object, which will deal with Content Provider
ContentResolver cr = getContentResolver();
// Fetch Sent SMS Message from Built-in Content Provider
Cursor c = cr.query(draftURI, reqCols, null, null, null);
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
tutorial link
Is there a way to figure out a contents URI for SMS data for a specific android device?
For example, I was able to locate the DB containing all messages following this.
SMS DB is located at ./dbdata/databases/com.android.providers.telephony/mmssms.db
However, I want to know the contents URI rather than the actual location (e.g. contents://sms). Is this possible? If not, how do I gather information about stored SMS messages from different devices that have different and unknown content URIs for SMS?
For example, these are the contents URI for some vendors:
LG: content://com.lge.messageprovider/msg/inbox
SAMSUNG: content://com.sec.mms.provider/message
SAMSUNG Galaxy A: content://com.btb.sec.mms.provider/message
General: content://sms/inbox
Why don't you use uri parser of Contentresolver, especially that you know content string.
Try this (in connection with Cursor):
Cursor cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);
cursor.moveTofirst();
//read all messages in your inbox
do
{
String message = "";
//read all data from all available columns for each message
for (int i = 0; i < cursor.getColumnCount(); i++)
{
message += " " + cursor.getComulnName(i) + ": " + cursor.getString(i);
//here do wathever you want with your message string
}
}
while(cursor.moveToNext());
cursor.close();
dont forget do add READ_SMS permission to your AndroidManifest.xml
I am implementing the methods discussed here How to Read MMS Data in Android
Here is the snippet.
ContentResolver contentResolver = getContentResolver();
final String[] projection = new String[]{"*"};
Uri uri = Uri.parse("content://mms-sms/conversations/");
Cursor query = contentResolver.query(uri, projection, null, null, null);
When I try to get the data through the cursor, I do not get the IDs of the MMS messages. I only get the IDs of the SMS messages. I have two MMS in my inbox and their address "number" do not show up.
In my application I need to read sms coming from only a number, and when i receive it I need to set it as read automatically, without setting it in the sms android application, but from my app. How can I do?
Thanks!
Let me update this:
ContentValues values = new ContentValues();
values.put("read",true);
getContentResolver().update(Uri.parse("content://sms/"),values, "_id="+SmsMessageId, null);
SmsMessageId is _id of message, which you find in SMS database.
A short example:
Uri uri = Uri.parse("content://sms/inbox");
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
while (cursor.moveToNext()) {
// Retrieve sms
// see column "address" for comparing
// Then update the sms and set the column "read" to 1
}