我想读的通话记录在Android [英] I want to read call logs in the android

查看:132
本文介绍了我想读的通话记录在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/5674156/how-can-i-retrieve-recently-used-contacts-in-android">How我可以找回最近采用的是Android联系人?

我想读的最近使用过的联系人。

I want to read recently used contacts.

任何人都知道如何做到这一点?

Anyone know how to do this?

推荐答案

1。创建观察报:

class CustomContentObserver extends ContentObserver {

        public CustomContentObserver(Handler handler) {
            super(handler);

        }

        @Override public boolean deliverSelfNotifications() { 
            return false; 
        }

        public void logCallLog() {
            long dialed;
            String columns[]=new String[] {
                    CallLog.Calls._ID, 
                    CallLog.Calls.NUMBER, 
                    CallLog.Calls.DATE, 
                    CallLog.Calls.DURATION, 
                    CallLog.Calls.TYPE};
            Cursor c;
            c = getContentResolver().query(Uri.parse("content://call_log/calls"),
                    columns, null, null, "Calls._ID DESC"); //last record first
            while (c.moveToNext()) {
                dialed=c.getLong(c.getColumnIndex(CallLog.Calls.DATE));                 
                Log.i("CallLog","type: " + c.getString(4) + "Call to number: "+number+", registered at: "+new Date(dialed).toString());
            }
        }

        public void onChange(boolean selfChange) {
            super.onChange(selfChange);
            Log.d("PhoneService", "StringsContentObserver.onChange( " + selfChange + ")");
            logCallLog();
        }

}

2。注册观察员:

 Uri mediaUri = android.provider.CallLog.Calls.CONTENT_URI;
        Log.d("PhoneService", "The Encoded path of the media Uri is "
                + mediaUri.getEncodedPath());
        CustomContentObserver custObser = new CustomContentObserver(handler);
        imageContentRsr.registerContentObserver(mediaUri, false, custObser);

编辑: 由于杰利贝恩(4.1),你现在需要两个权限

As of Jellybean (4.1), you now need the two permission

    <uses-permission android:name="android.permission.READ_CALL_LOG" />

对于这项工作,而不是抛出一个权限拒绝例外

For this to work and not throw a Permission Denial exception

这篇关于我想读的通话记录在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆