如何解决Android SMS:如何识别SMS的各个部分
我正在为个人使用开发短信应用。
我正在使用ContentObserver监视SMS。
现在有时长消息会分成多个部分。
因此,很难确定SMS的哪一部分。
假设我与A与B交谈,C也向B发送消息。
现在A的信息是“原始部分” + 2其他部分。
B receives Original(First part) From A
B receives Original(First part) From C
B receives Different message From A
B receives Second part From A
B receives Second part From C
B receives Third part From A
我们可以合并各个部分吗?
现在我正在访问下面的列,但不确定哪一列会有所帮助。
@Override
public void onChange(boolean selfChange) {
Log.i(TAG,"Message Changed");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& moContext
.checkCallingOrSelfPermission(Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED) {
Log.i(TAG,"READ_SMS permission not granted");
return;
}
if (moContext == null) {
Log.i(TAG,"moContext null");
return;
}
Uri loUriAllMessages = Uri.parse("content://sms/");
Cursor loCursor = moContext.getContentResolver().query(loUriAllMessages,null,"_id DESC");
try {
if (loCursor != null && loCursor.getCount() > 0) {
if (loCursor.movetoFirst()) {
int liSubMessageId = -10;
int liThreadId = -10;
String lsPerson = "-10";
String lsprotocol = "-10";
String lsstatus = "-10";
String lssubject = "-10";
String lsreply_path_present = "-10";
int liRead = -10;
int lilocked = -10;
int liseen = -10;
int liMessageId = loCursor.getInt(loCursor.getColumnIndex("_id"));
if (!loCursor.isNull(loCursor.getColumnIndex("sub_id"))) {
liSubMessageId = loCursor.getInt(loCursor.getColumnIndex("sub_id"));
}
if (!loCursor.isNull(loCursor.getColumnIndex("thread_id"))) {
liThreadId = loCursor.getInt(loCursor.getColumnIndex("thread_id"));
}
if (!loCursor.isNull(loCursor.getColumnIndex("read"))) {
liRead = loCursor.getInt(loCursor.getColumnIndex("read"));
}
if (!loCursor.isNull(loCursor.getColumnIndex("locked"))) {
lilocked = loCursor.getInt(loCursor.getColumnIndex("locked"));
}
if (!loCursor.isNull(loCursor.getColumnIndex("seen"))) {
liseen = loCursor.getInt(loCursor.getColumnIndex("seen"));
}
if (!loCursor.isNull(loCursor.getColumnIndex("person"))) {
lsPerson = loCursor.getString(loCursor.getColumnIndex("person"));
}
if (!loCursor.isNull(loCursor.getColumnIndex("protocol"))) {
lsprotocol = loCursor.getString(loCursor.getColumnIndex("protocol"));
}
if (!loCursor.isNull(loCursor.getColumnIndex("reply_path_present"))) {
lsreply_path_present = loCursor.getString(loCursor.getColumnIndex("reply_path_present"));
} if (!loCursor.isNull(loCursor.getColumnIndex("status"))) {
lsstatus = loCursor.getString(loCursor.getColumnIndex("status"));
}
if (!loCursor.isNull(loCursor.getColumnIndex("subject"))) {
lssubject = loCursor.getString(loCursor.getColumnIndex("subject"));
}
final String lsMessageText = loCursor.getString(loCursor.getColumnIndex("body"));
final String lsPhoneNumber = loCursor.getString(loCursor.getColumnIndex("address"));
final String lsDate = loCursor.getString(loCursor.getColumnIndex("date"));
String lsType = loCursor.getString(loCursor.getColumnIndex("type")).trim();
Log.i(TAG,"*********************************Start***************************************");
Log.i(TAG,"loCursor Type : " + lsType);
Log.i(TAG,"loCursor Message Id : " + liMessageId);
Log.i(TAG,"loCursor Sub Message Id : " + liSubMessageId);
Log.i(TAG,"loCursor Thread Message Id : " + liThreadId);
Log.i(TAG,"loCursor Read Message : " + liRead);
Log.i(TAG,"loCursor Phone number: " + lsPhoneNumber);
Log.i(TAG,"loCursor Message Text: " + lsMessageText);
Log.i(TAG,"loCursor Date : " + lsDate);
Log.i(TAG,"loCursor Person : " + lsPerson);
Log.i(TAG,"loCursor protocol : " + lsprotocol);
Log.i(TAG,"loCursor status : " + lsstatus);
Log.i(TAG,"loCursor subject : " + lssubject);
Log.i(TAG,"loCursor locked : " + lilocked);
Log.i(TAG,"loCursor reply_path_present : " + lsreply_path_present);
Log.i(TAG,"loCursor seen : " + liseen);
Log.i(TAG,"**********************************End**************************************");
}
}
} catch (Exception e) {
} finally {
if (loCursor != null)
loCursor.close();
}
super.onChange(selfChange);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。