Reputation: 703
I'm trying to read the SMS messages from the user's inbox, but I only get the Number, as cur.getString()
allways returns NULL to me, After an Index of 2...
Here is my code :
TextView view = (TextView)findViewById(R.id.textView1);
Uri uriSMSURI = Uri.parse("content://sms/inbox");
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null,null);
String sms = "";
while (cur.moveToNext())
{
sms += "From :" + cur.getString(2) + " : " + cur.getString(11)+"\n";
Log.i("MyApp", "A " + cur.getString(2) + " " + cur.getString(3));
}
view.setText(sms);
I've checked, and cur.getString(3)
and above, allways returns null to me...
What is my error?
Thanks!
Edit :
thanks to simas, I've seen that the body
field that contains the message data, is field number 12 in the Cursor (cur)
, and not 11. so changing it from 11 to 12 fixed it.
Thanks simas!
Upvotes: 0
Views: 224
Reputation: 222
try this:
cur.moveToFirst();
if (cur != null) {
do {
sms += "From :" + cur.getString(2) + " : " + cur.getString(11)+"\n";
Log.i("MyApp", "A " + cur.getString(2) + " " + cur.getString(3));
}while(cur.moveToNext());
}
Upvotes: 1