我试图从发件箱短信中获取数据。 这是我的代码。
Cursor cursor = getContentResolver().query(
Uri.parse("content://sms/sent"), null, null, null, null);
String dateColumn = cursor.getColumnIndex("date");
String bodyColumn = cursor.getColumnIndex("body");
String addressColumn = cursor.getColumnIndex("address");
output += new StringBuilder("\nMessage to: ").append(addressColumn)
.append("\n\n").append(bodyColumn);
Toast.makeText(context, output, Toast.LENGTH_LONG).show();
String dateColumn = cursor.getColumnIndex("date");
String bodyColumn = cursor.getColumnIndex("body");
String addressColumn = cursor.getColumnIndex("address");
output += new StringBuilder("\nMessage to: ").append(addressColumn)
.append("\n\n").append(bodyColumn);
Toast.makeText(context, output, Toast.LENGTH_LONG).show();
但是当我启动程序时会出错,并要求“强行关闭”。
任何人都可以帮助我吗?
答案 0 :(得分:1)
您需要在获取游标值之前添加此命令:
cursor.moveToNext();