我已经知道如何从收件箱中读取消息,但我想实现一个 android 应用程序来读取仅交易消息并将其显示在列表视图中,其中包含交易金额、贷记借方等。对于我的完整代码。 当前获取短信数据的完整代码。如何根据要求过滤短信数据。
public List<SmsInfo> getSmsInfo() {
String[] projection = new String[] { "_id", "address", "person",
"body", "date", "type" };
// @SuppressWarnings("deprecation")
// Cursor cursor = activity.managedQuery(uri, projection, null, null,
// "date desc");
ContentResolver cr = activity.getContentResolver();
Cursor cursor = cr.query(uri, projection, null, null, "date desc");
int nameColumn = cursor.getColumnIndex("person");
int phoneNumberColumn = cursor.getColumnIndex("address");
int smsbodyColumn = cursor.getColumnIndex("body");
int dateColumn = cursor.getColumnIndex("date");
int typeColumn = cursor.getColumnIndex("type");
if (cursor != null) {
int i = 0;
while (cursor.moveToNext() && i++ < 20) {
SmsInfo smsInfo = new SmsInfo();
smsInfo.setName(cursor.getString(nameColumn));
smsInfo.setDate(dateFromLongToString(cursor.getString(dateColumn)));
smsInfo.setPhoneNumber(cursor.getString(phoneNumberColumn));
smsInfo.setSmsbody(cursor.getString(smsbodyColumn));
smsInfo.setType(cursor.getString(typeColumn));
String personName = getPeople2(smsInfo.getPhoneNumber());
smsInfo.setName(null == personName ? smsInfo.getPhoneNumber()
: personName);
infos.add(smsInfo);
}
cursor.close();
}
return infos;
}