Hello, when I send an SMS on my Android emulator, it goes to the content provider:
content://sms/sent
right?
So I wanted to get the last sent SMS from the content provider. So I used this Uri as you can see above, and, I used the method query, with the Content Resolver Object. And I got the cursor, and used the movetofirst() method, so I would have the last sent SMS. Check the code below. I hope it helps.
package com.sys;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.net.Uri;
import android.database.Cursor;
public class SMS extends Activity {
Button btnVerSms;
EditText txtFinal;
final Uri CONTENT_URI = Uri.parse("content://sms/sent");
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnVerSms= (Button)findViewById(R.id.btnVerSms);
txtFinal = (EditText)findViewById(R.id.txtFinal);
btnVerSms.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Cursor cursor = getContentResolver().query(CONTENT_URI, null, null, null, null);
String body = null;
if(cursor.moveToFirst()){
body = cursor.getString(cursor.getColumnIndexOrThrow("body")).toString();
}
txtFinal.setText(body);
}
});
}
}