I want to read the conversation and put it in ListView. How can I do it?
I have two TextViews for each row. I want to set them by using BaseAdapter.
By using this, content://mms-sms/conversations/
*Update:*
I tried doing this:
public ArrayList<String> number = new ArrayList<String>();
public ArrayList<String> body = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(new BaseAdapter(){
public int getCount() {
return number.size();
}
public Object getItem(int position) {
return number.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.contact_row, null);
TextView textView = (TextView) view.findViewById(R.id.textView1);
textView.setText(number.get(position));
return view;
}});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void getcon()
{
Uri uriSMSURI = Uri.parse("content://mms-sms/conversations/");
Cursor cursor = getContentResolver().query(uriSMSURI, null, null, null, "date desc");
cursor.moveToFirst();
while (cursor.moveToNext())
{
String address = cursor.getString(cursor.getColumnIndex("address"));
//String body = cursor.getString(cursor.getColumnIndexOrThrow("body"));
//String read = cursor.getString(cursor.getColumnIndexOrThrow("read"));
String contactName = address;
Uri Nameuri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address));
Cursor cs= getContentResolver().query(Nameuri, new String[]{PhoneLookup.DISPLAY_NAME},PhoneLookup.NUMBER+"='"+address+"'",null,null);
if(cs.getCount()>0)
{
cs.moveToFirst();
contactName = cs.getString(cs.getColumnIndex(PhoneLookup.DISPLAY_NAME));
}
number.add(contactName);
}
}