I am using 2.1 platform I can retrieve the SMS details by using the below code.But the number and the SMS Body is only displayed, Name hasn’t come yet, what can I do to retrieve the Name also ?
code
public class SMSActivity extends Activity {
ListView lview;
String Body = "" ;
ArrayList<String> smslist=new ArrayList<String>();
ArrayAdapter<String> itemAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lview =(ListView)findViewById(R.id.lv);
itemAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,smslist);
lview.setAdapter(itemAdapter);
ContentResolver cr = getContentResolver();
Cursor c = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);
while(c.moveToNext()){
Number = c.getString(c.getColumnIndexOrThrow("address"));
Body = c.getString(c.getColumnIndexOrThrow("body")).toString();
smslist.add( Number + ":" +"\n"+ Body);
}
itemAdapter.notifyDataSetChanged();
c.close();
}
}
How to solve this problem ?
You have Number right!! now pass this number into this method it will return you contact name of corresponding number.
add below permission
<uses-permission android:name="android.permission.READ_CONTACTS" />in your manifest file to Read_contact data.
for your code replace this code
with below