i want read all sms in draft box of android i write an app that can read all sms in inbox sent box
but i dont know uri path of draft box in android
i should replace uri path of draft box with inbox to read all sms that are in drafts
but what is it?
sms objSms = new sms();
Uri message = Uri.parse("content://sms/sent");
ContentResolver cr = context.getContentResolver();
Cursor c = cr.query(message, null, null, null, null);
int totalSMS = c.getCount();
Log.i("READDDDDDDDD INBOX",totalSMS+"***************************" );
if (c.moveToFirst()) {
for (int i = 0; i < totalSMS; i++) {
objSms = new sms();
objSms.setPhone(c.getString(c
.getColumnIndexOrThrow("address")));
objSms.setMessage(c.getString(c.getColumnIndexOrThrow("body")));
objSms.setDate_time(c.getString(c.getColumnIndexOrThrow("date")));
ars.add(objSms);
c.moveToNext();
}
}
c.close();
return ars;
SMS draft URI is
content://sms/drafts/
Uri message = Uri.parse("content://sms/drafts/");
The whole list of SMS uris are:
Inbox = "content://sms/inbox"
Failed = "content://sms/failed"
Queued = "content://sms/queued"
Sent = "content://sms/sent"
Draft = "content://sms/draft"
Outbox = "content://sms/outbox"
Undelivered = "content://sms/undelivered"
All = "content://sms/all"
Conversations = "content://sms/conversations"
"content://mms-sms/conversations"
Some are documented and rest are not/
public static final Uri CONTENT_URI =
Uri.parse("content://sms/draft");
for more help check this
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.2.2_r1/android/provider/Telephony.java
Related
I am working on android application (as a final year project in my university) which backup and restores contacts, messages, calendar, call logs etc. I started working on it yesterday and until now I am able to get the message conversations through ContentResolver like this:
private void MsgBackup(){
try {
Uri uri = Uri.parse("content://sms");
//Uri uri = Uri.parse("content://mms-sms/conversations/");
ContentResolver contentResolver = getContentResolver();
final String[] projection = new String[]{"*"};
Cursor SMSL = contentResolver.query(uri, projection, null, null, null);
int msgscount = SMSL.getCount();
msgs = new String[SMSL.getCount()][2];
int i = 0;
while (SMSL.moveToNext()) {
address = SMSL.getString(SMSL.getColumnIndex("address"));
body = SMSL.getString(SMSL.getColumnIndex("body"));
msgs[i][0] = address;
msgs[i][1] = body;
i++;
}
SMSL.close();
//will do something here to backups msgs array
}catch (Exception e){
e.printStackTrace();
Toast.makeText(getApplicationContext(),"Error Fetching messages, check permissions!",Toast.LENGTH_LONG).show();
}
}
What I am worried about is "Restoring them". I read somewhere that it is not possible to restore messages without root access. If so, then how come the applications in the market do this job without root access?
Im building a app that is reading last sms from spec number (vb# 8888). Code is working great. I only have one prob. When i get a new sms from other number (vb# 7777)my code stops reading sms from (v#8888). if i delete the new sms from (7777) than my code strats working again. I'm using this to update a string in my app. Can someone help me
This is my code
Uri mSmsinboxQueryUri = Uri.parse("content://sms/inbox");
Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri, null, null, null, null);
String[] columns = new String[]{"address", "body"};
if(cursor1.moveToFirst()) {
String address = cursor1.getString(cursor1.getColumnIndex(columns[0]));
if address.equalsIgnoreCase("+597*******")) {
body = cursor1.getString(cursor1.getColumnIndex(columns[3]));
Koers = (TextView) findViewById(R.id.Koersdiedag);
Koers.setText(body);//body
Your code is just reading the most recent message in the inbox, whomever it's from. If you want the most recent message from that particular number, you can adjust your query to match the number, and limit the results to one record.
Uri mSmsinboxQueryUri = Uri.parse("content://sms/inbox");
String[] projection = {"address", "body"};
String phoneNumber = "+597*******";
Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri,
projection,
"address = ?",
new String[] {phoneNumber},
"date DESC LIMIT 1");
if (cursor1 != null && cursor1.moveToFirst()) {
body = cursor1.getString(cursor1.getColumnIndex("body"));
Koers = (TextView) findViewById(R.id.Koersdiedag);
Koers.setText(body);
}
In the original SMS app of android i can check the details of a received sms and it wil show me the time and date it was sent by the sender and the time i received this message.
I am interested in the time difference between these 2
I can get the time i received the sms via this code. how can i extend this so that i also get the time it was sent?
Uri uri = Uri.parse("content://sms");
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
if (cursor.moveToFirst()) {
for (int i = 0; i < cursor.getCount(); i++) {
String body = cursor.getString(cursor.getColumnIndexOrThrow("body"))
.toString();
String number = cursor.getString(cursor.getColumnIndexOrThrow("address"))
.toString();
String date = cursor.getString(cursor.getColumnIndexOrThrow("date"))
.toString();
Date smsDayTime = new Date(Long.valueOf(date));
String type = cursor.getString(cursor.getColumnIndexOrThrow("type"))
.toString();
I am working on an sms app.By using sms content provider I got all the fields.
Uri uriSms = Uri.parse("content://sms/inbox");
Cursor c = context.getContentResolver().query(uriSms, null,null,null,null);
_id
thread_id
address
person
date
read
status
type
subject
body
locked
I could able to do all basic operations using the above fields.Now I want to make a sms locked state. How can I do that?.From status field I am always getting -1.What that means.I checked with both inbox and outbox.Please help me friends
Sms.CONTENT_URI= Uri.parse("content://sms");
Mms.CONTENT_URI = Uri.parse("content://mms");
private void lockMessage(MessageItem msgItem, boolean locked) {
Uri uri;
if ("sms".equals(msgItem.mType)) {
uri = Sms.CONTENT_URI;
} else {
uri = Mms.CONTENT_URI;
}
final Uri lockUri = ContentUris.withAppendedId(uri, msgItem.mMsgId);
final ContentValues values = new ContentValues(1);
values.put("locked", locked ? 1 : 0);
new Thread(new Runnable() {
public void run() {
getContentResolver().update(lockUri,
values, null, null);
}
}).start();
}
Just reminder, everything above is not include in SDK so carefull in usage.
I've wrote the following code, to get the whole conversation between the user and a number:
Uri SMS_INBOX = Uri.parse("content://sms/");
String selection = "thread_id = " + thread_id;
final String[] projection = new String[] { "*" };
Cursor c = getContentResolver().query(SMS_INBOX, projection, selection,null, "date");
startManagingCursor(c);
String[] body = new String[c.getCount()];
String[] address = new String[c.getCount()];
if (c.moveToFirst()) {
for (int j = 0; j < c.getColumnCount(); j++)
Log.w("ColumnName", c.getColumnName(j));
for (int i = 0; i < c.getCount(); i++) {
body[i] = c.getString(c.getColumnIndexOrThrow("body")).toString();
address[i] = c.getString(c.getColumnIndexOrThrow("address")).toString();
Log.d("address-" + i, address[i]);
Log.d("body-" + i, body[i]);
String subject = c.getString(c.getColumnIndexOrThrow("_id")).toString();
Log.d("_id-" + i, subject);
String thread = c.getString(c.getColumnIndexOrThrow("thread_id")).toString();
Log.d("thread_id-" + i, subject);
Log.d("----", "----");
c.moveToNext();
}
}
Via this code, i get all the messages in a conversation. The problem is, I can't figure out which number is sending which message. If i get the column "address" it returns the same number all the time (actually it returns the other person's number only), so I can't keep record of whether the message I just got through this code was sent by the user or the other number.
The column will always gives second persons number only.If you want to differentiate sent message and received message you have to use column 'type'.
body[i] = c.getString(c.getColumnIndexOrThrow("body")).toString();
if(c.getString(c.getColumnIndex("type")).equalsIgnoreCase("1")){
// sms received
msg_state[i]=1;
}
else {
//sms sent
msg_state[i]=0;
}
No You can easily identify the sent sms and received sms.