Java getContentResolver()。使用调用日志进行查询

Java getContentResolver()。使用调用日志进行查询,java,android,calllog,Java,Android,Calllog,我正在开发一个Android应用程序。我需要获取通话记录,以获取有关传出通话的信息。我正在使用这个(来自这里的某个主题): 我也可以使用这个较新的代码: Cursor c = getContentResolver().query(CallLog.Calls.CONTENT_URI,null, null,null, null); 但在这两个例子中,我的应用程序在手机上甚至在模拟器上崩溃。我试图解决这个问题,但我认为我发现这个查询行是问题所在,但只适用于CallLog。 例如,当我使用类似的短信代

我正在开发一个Android应用程序。我需要获取通话记录,以获取有关传出通话的信息。我正在使用这个(来自这里的某个主题):

我也可以使用这个较新的代码:

Cursor c = getContentResolver().query(CallLog.Calls.CONTENT_URI,null, null,null, null);
但在这两个例子中,我的应用程序在手机上甚至在模拟器上崩溃。我试图解决这个问题,但我认为我发现这个查询行是问题所在,但只适用于CallLog。 例如,当我使用类似的短信代码时,everythink工作正常

public StringBuffer getOutgoingSMSContent() {

        ContentResolver contentResolver = getContentResolver();
        Uri uri = Uri.parse("content://sms/sent/");
        StringBuffer messagedata = new StringBuffer();
        int count = 0;

        Cursor cursor = contentResolver.query(uri, null, null, null, null);
        if (cursor.getCount() != 0) {
            if (cursor.moveToFirst()) {
                do {
                    messagedata.append("Outgoing message count: " + (count + 1)
                            + "\n");
                    for (int m = 0; m < cursor.getColumnCount(); m++) {
                        if (cursor.getColumnName(m).equalsIgnoreCase("address")
                                || cursor.getColumnName(m).equalsIgnoreCase(
                                        "date")
                                || cursor.getColumnName(m).equalsIgnoreCase(
                                        "body")
                                || cursor.getColumnName(m).equalsIgnoreCase(
                                        "type")) {
                            messagedata.append(cursor.getColumnName(m) + "  : "
                                    + cursor.getString(m));
                            messagedata.append("\n");
                        }
                    }
                    messagedata.append("\n");
                    count++;
                } while (cursor.moveToNext());
            }
        }
        cursor.close();
        cursor = null;
        return messagedata;
    }
public StringBuffer getoutgoingsmscocontent(){
ContentResolver ContentResolver=getContentResolver();
Uri=Uri.parse(“content://sms/sent/");
StringBuffer messagedata=新的StringBuffer();
整数计数=0;
Cursor Cursor=contentResolver.query(uri,null,null,null);
if(cursor.getCount()!=0){
if(cursor.moveToFirst()){
做{
messagedata.append(“传出消息计数:”+(计数+1)
+“\n”);
对于(int m=0;m

有什么想法吗

看看LogCat,看看你为什么崩溃:我猜你没有
READ\u CONTACTS
权限,但这只是一个猜测。非常感谢!我认为LogCat是无用的,现在我甚至知道如何使用它,我错了!是的,这就是问题所在。。我已经开发了一个全面的联系人管理器应用程序,但在Android 5.1上阅读呼叫日志时,突然之间,这种情况经常发生。
public StringBuffer getOutgoingSMSContent() {

        ContentResolver contentResolver = getContentResolver();
        Uri uri = Uri.parse("content://sms/sent/");
        StringBuffer messagedata = new StringBuffer();
        int count = 0;

        Cursor cursor = contentResolver.query(uri, null, null, null, null);
        if (cursor.getCount() != 0) {
            if (cursor.moveToFirst()) {
                do {
                    messagedata.append("Outgoing message count: " + (count + 1)
                            + "\n");
                    for (int m = 0; m < cursor.getColumnCount(); m++) {
                        if (cursor.getColumnName(m).equalsIgnoreCase("address")
                                || cursor.getColumnName(m).equalsIgnoreCase(
                                        "date")
                                || cursor.getColumnName(m).equalsIgnoreCase(
                                        "body")
                                || cursor.getColumnName(m).equalsIgnoreCase(
                                        "type")) {
                            messagedata.append(cursor.getColumnName(m) + "  : "
                                    + cursor.getString(m));
                            messagedata.append("\n");
                        }
                    }
                    messagedata.append("\n");
                    count++;
                } while (cursor.moveToNext());
            }
        }
        cursor.close();
        cursor = null;
        return messagedata;
    }