我也想访问短信日志。但是我找不到任何办法,我已经使用CallLog.Calls访问了呼叫日志,它无法列出短信日志。 下面的代码只列出了通话记录,但并未列出所有日志,甚至没有列出短信日志(短信日志意味着因接收和发送短信而创建的日志)。请帮我找到检索短信日志的方法。请尽可能先生。
Cursor cursor = managedQuery(CallLog.Calls.CONTENT_URI, null, null,
null, Calls.DATE + " DESC");
// cursor is inited
cursor.moveToFirst();
String name;
String number;
int type;
do {
name = "";
number = "";
type = -1;
try {
number = cursor.getString(cursor
.getColumnIndex(CallLog.Calls.NUMBER));
type = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE));
try {
name = cursor.getString(cursor
.getColumnIndex(CallLog.Calls.CACHED_NAME));
} catch (Exception e) {
} finally {
if (name == null || name.equals("")) {
name = "UNKNOWN";
}
}
Log.e("My App", name + " : "+number + " : "+type);
} catch (Exception e) {
Log.e("My App", "Error in creation");
}
} while (cursor.moveToNext());
答案 0 :(得分:2)
这只是建议。你会得到更好的答案而不是......
看看你是否想获得sms日志然后使用下面的代码..你已经得到了通话记录..所以如果你想在一个列表中混合使用call和sms log,那么你必须按日期这样做.. < / p>
在通话记录中,您可以获得日期&amp;时间 在短信中你也得到日期&amp;时间
短信日志代码......
把它放在方法中并以你自己的方式使用..
CharSequence contentTitle = getString(R.string.app_name);
final ProgressDialog progDailog = ProgressDialog.show(
All_logs_tab.this, contentTitle, "Please wait...", true);
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
/* finish sms load */
}
};
new Thread() {
public void run() {
try {
Uri myMessage = Uri.parse("content://sms/");
ContentResolver cr = con.getContentResolver();
Cursor c = cr.query(myMessage, new String[] { "_id",
"address", "date", "body", "read" }, null,
null, null);
startManagingCursor(c);
getSmsLogs(c, con);
} catch (Exception e) {
}
handler.sendEmptyMessage(0);
progDailog.dismiss();
}
}.start();
............................................... .. 我在数组列表中添加了所有sms细节
ArrayList<String> sms_id = new ArrayList<String>();
ArrayList<String> sms_num = new ArrayList<String>();
ArrayList<String> sms_Name = new ArrayList<String>();
ArrayList<String> sms_dt = new ArrayList<String>();
ArrayList<String> sms_body = new ArrayList<String>();
............................................... .........
public void getSmsLogs(Cursor c, Context con) {
if (sms_num.size() > 0) {
sms_id.clear();
sms_num.clear();
sms_Name.clear();
sms_body.clear();
sms_dt.clear();
}
try {
if (c.moveToFirst()) {
do {
if (c.getString(c.getColumnIndexOrThrow("address")) == null) {
c.moveToNext();
continue;
}
String _id = c.getString(c.getColumnIndexOrThrow("_id"))
.toString();
String Number = c.getString(
c.getColumnIndexOrThrow("address")).toString();
String dat = c.getString(c.getColumnIndexOrThrow("date"))
.toString();
String as = (String) get_dt(dat, "dd/MM/yyyy, hh.mma");
String Body = c.getString(c.getColumnIndexOrThrow("body"))
.toString();
String name = getContactDisplayNameByNumber("" + Number,
con);
if (name.length() <= 0 || name.length() == 1) {
name = "no name";
}
sms_id.add(_id);
sms_num.add(Number);
sms_Name.add("" + name);
sms_body.add(Body);
sms_dt.add(as);
} while (c.moveToNext());
}
c.close();
} catch (Exception e) {
e.printStackTrace();
}
}
答案 1 :(得分:0)
您需要SMS消息表的URI,这将检索您的数据。然而,它可以在基本源代码中找到; Google不建议您这样做。
答案 2 :(得分:0)
使用此链接Android call logs来检索通话记录。对于sms,使用 SMS_URI =“content:// sms”也是如此,但不建议这样做,因为它不是公共URi。