[英]Reading SMS messages from Inbox
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... 我正在尝试从用户的收件箱中读取SMS消息,但我只能获取Number,因为
cur.getString()
始终向我返回NULL,在索引为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... 我已经检查过,并且在
cur.getString(3)
及以上版本中, cur.getString(3)
向我返回null。
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. 编辑:感谢simas,我已经看到包含消息数据的
body
字段是Cursor( cur)
中的字段编号12,而不是11。因此将其从11更改为12可以修复它。 Thanks simas! 谢谢西玛斯!
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());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.