public class MainActivity extends Activity {
String address, name, date, msg, type;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn =(Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Uri mSmsinboxQueryUri = Uri.parse("content://sms/sent");
Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri,
new String[] { "_id", "thread_id", "address", "person", "date",
"body", "type" }, null, null, null);
startManagingCursor(cursor1);
String[] columns = new String[] { "address", "person", "date", "body","type" };
if (cursor1.getCount() > 0) {
String count = Integer.toString(cursor1.getCount());
//Log.e("Count",count);
System.out.println("Count:" + count);
while (cursor1.moveToNext()){
address = cursor1.getString(cursor1.getColumnIndex(columns[0]));
name = cursor1.getString(cursor1.getColumnIndex(columns[1]));
date = cursor1.getString(cursor1.getColumnIndex(columns[2]));
msg = cursor1.getString(cursor1.getColumnIndex(columns[3]));
type = cursor1.getString(cursor1.getColumnIndex(columns[4]));
}
}
Toast.makeText(getApplicationContext(), address + "\n" + name + "\n" + date + "\n" + msg + "\n" + type, Toast.LENGTH_LONG).show();
}
});
}
}
I have a code from which I can get the first sms from "Sent SMS" in string format. I want to get all sms from sent box one by one starting from the first. I would like to save them in SQLite database. The below code shows the first sent sms in Toast but how to get all the sent sms? Any help would be appreciated.
Aucun commentaire:
Enregistrer un commentaire