gpt4 book ai didi

android - 如何列出日志列表中的所有调用日志,包括短信和电子邮件日志?

转载 作者:行者123 更新时间:2023-11-29 22:03:33 37 4
gpt4 key购买 nike

我也想访问短信日志。但我找不到任何方法,我已经使用 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());

最佳答案

这只是建议。你会得到比这个更好的答案......

看看你是否想要获取短信日志然后使用下面的代码..你已经获得了通话记录..所以如果你想在一个列表中混合通话和短信登录那么你必须在日期之前完成..

在通话记录中你会得到日期和时间在短信中你也可以得到日期和时间

短信日志代码...

将其放入方法中并使用您自己的方式..

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();

................................................ ..我在数组列表中添加了所有短信详细信息

     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();
}
}

关于android - 如何列出日志列表中的所有调用日志,包括短信和电子邮件日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11356093/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com