2

我正在编写代码以获取用户在其 android 设备中执行的所有活动的日志,并且我成功了。代码如下所示。我有两个问题

Que 1 :- 如何获取一整天的日志?
Que 2 :- 如何获取和显示被叫号码、短信号码、短信号码等?

由于 stackoverflow 限制,完整输出未显示,因为它超过 6000 个字符

private String getFormattedKernelVersion() 
{
    String procVersionStr;

    try {
        BufferedReader reader = new BufferedReader(new FileReader("/proc/version"), 256);
        try {
            procVersionStr = reader.readLine();
        } finally {
            reader.close();
        }

        final String PROC_VERSION_REGEX =
            "\\w+\\s+" + /* ignore: Linux */
            "\\w+\\s+" + /* ignore: version */
            "([^\\s]+)\\s+" + /* group 1: 2.6.22-omap1 */
            "\\(([^\\s@]+(?:@[^\\s.]+)?)[^)]*\\)\\s+" + /* group 2: (xxxxxx@xxxxx.constant) */
            "\\([^)]+\\)\\s+" + /* ignore: (gcc ..) */
            "([^\\s]+)\\s+" + /* group 3: #26 */
            "(?:PREEMPT\\s+)?" + /* ignore: PREEMPT (optional) */
            "(.+)"; /* group 4: date */

        Pattern p = Pattern.compile(PROC_VERSION_REGEX);
        Matcher m = p.matcher(procVersionStr);

        if (!m.matches()) {
            Log.e(TAG, "Regex did not match on /proc/version: " + procVersionStr);
            return "Unavailable";
        } else if (m.groupCount() < 4) {
            Log.e(TAG, "Regex match on /proc/version only returned " + m.groupCount()
                    + " groups");
            return "Unavailable";
        } else {
            return (new StringBuilder(m.group(1)).append("\n").append(
                    m.group(2)).append(" ").append(m.group(3)).append("\n")
                    .append(m.group(4))).toString();
        }
    } catch (IOException e) {  
        Log.e(TAG,
            "IO Exception when getting kernel version for Device Info screen",
            e);

        return "Unavailable";
    }

输出是:

   --------- /dev/log/system 的开头
    01-23 15:59:59.042 I/ActivityManager(247): 为服务 com.sonyericsson.updatecenter/.UpdateCenterService 启动 proc com.sonyericsson.updatecenter: pid=5181 uid=10013 gids={3003, 2001, 1015}
    01-23 16:00:09.042 I/ActivityManager(247): 为服务 com.scoreloop.magicbox/.service.MagicBoxService 启动 proc com.scoreloop.magicbox: pid=5189 uid=10023 gids={3003, 1015}
   服务 com.sonyericsson.secureclockservice/.SecureClockStartupService 的 rvice:pid=5236 uid=10104 gids={3003}
    01-23 16:14:35.709 I/TelephonyRegistry(247): notifyDataConnection: state=2 isDataConnectivityPossible=true reason=null interfaceName=rmnet0 networkType=2
    01-23 16:19:33.351 I/ActivityManager(247):不再需要 com.sonyericsson.crashmonitor(pid 4080):隐藏 #16
    01-23 16:19:33.351 I/ActivityManager(247): 24960ms 内不再需要 com.es.BootService
01-23 16:24:06.179 W/ActivityManager(247):计划在 34957 毫秒内重新启动崩溃的服务 com.sonyericsson.updatecenter/.UpdateCenterService
01-23 16:24:06.179 W/ActivityManager(247):计划在 44951 毫秒内重新启动崩溃的服务 com.scoreloop.magicbox/.service.MagicBoxService
01-23 16:24:11.149 I/ActivityManager(247):为服务 com.sonyericsson.android.datamonitor/com.sonyericsson.app.costcontrol.service.DataTrafficService 启动 proc com.sonyericsson.android.datamonitor:pid=5392 uid =10058 gids={3003}
01-23 16:27:28.838 I/ActivityManager(247): 为服务 com.facebook.katana/.service.MediaUploadService 启动 proc com.facebook.katana: pid=5399 uid=10024 gids={3003, 1006, 1015}
01-23 16:29:38.491 I/ActivityManager(247): 为服务 com.wsandroid.suite/.core.services.BootService 启动 proc com.wsandroid.suite: pid=5425 uid=10126 gids={3003, 1015, 1007}
01-23 16:29:48.491 I/ActivityManager(247): 为服务 com.sonyericsson.updatecenter/.UpdateCenterService 启动 proc com.sonyericsson.updatecenter: pid=5435 uid=10013 gids={3003, 2001, 1015}
01-23 16:34:05.759 I/ActivityManager(247): 为服务 com.scoreloop.magicbox/.service.MagicBoxService 启动 proc com.scoreloop.magicbox: pid=5445 uid=10023 gids={3003, 1015}
01-23 16:45:22.551 I/TelephonyRegistry(247): notifyDataConnection: state=0 isDataConnectivityPossible=false reason=null interfaceName=null networkType=2
01-23 16:45:22.571 I/TelephonyRegistry(247): notifyDataConnection: state=1 isDataConnectivityPossible=true reason=null interfaceName=null networkType=2
01-23 16:45:22.941 I/ActivityManager(247): 为广播 com.sonyericsson.appshare/.backend.SyncSchedulerReceiver 启动 proc com.sonyericsson.appshare: pid=5467 uid=10138 gids={3003, 1015}
01-23 16:45:23.091 I/ActivityManager(247): 启动 proc com.google.android.gm 广播 com.google.android.gm/.downloadprovider.DownloadReceiver: pid=5475 uid=10018 gids={3003, 1015}
01-23 16:45:28.901 I/TelephonyRegistry(247): notifyDataConnection: state=2 isDataConnectivityPossible=true reason=null interfaceName=rmnet0 networkType=2
01-23 16:53:41.072 I/ActivityManager(247): 启动 proc com.google.android.apps.maps:BackgroundFriendService 服务
01-23 17:04:39.991 I/ActivityManager(247): 为服务 com.scoreloop.magicbox/.service.MagicBoxService 启动 proc com.scoreloop.magicbox: pid=5611 uid=10023 gids={3003, 1015}
01-23 17:04:49.991 I/ActivityManager(247): 为服务 com.sonyericsson.updatecenter/.UpdateCenterService 启动 proc com.sonyericsson.updatecenter: pid=5630 uid=10013 gids={3003, 2001, 1015}
01-23 17:05:28.529 V/BackupManagerService(247):已请求备份,但没有任何待处理
01-23 17:13:59.866 I/TelephonyRegistry(247): notifyDataConnection: state=3 isDataConnectivityPossible=true reason=2GVoiceCallStarted interfaceName=rmnet0 networkType=2
01-23 17:13:59.886 I/ActivityManager(247): 启动 proc com.facebook.orca 用于广播 com.facebook.orca/.phone.TelephonyReceiver: pid=5659 uid=10148 gids={3003, 1015, 1006}
01-23 17:14:00.036 D/StatusBarService(313):通知有fullScreenIntent;发送全屏意图
01-23 17:14:00.036 I/ActivityManager(247):开始:Intent { act=android.intent.action.MAIN flg=0x10840000 cmp=com.android.phone/.SemcInCallScreen } 来自 pid -1
01-23 17:14:00.746 W/WindowManager(247): 迭代次数过多后布局重复被跳过
01-23 17:14:00.746 W/WindowManager(247): 迭代次数过多后布局重复被跳过
01-23 17:14:00.746 W/WindowManager(247): 迭代次数过多后布局重复被跳过
01-23 17:14:00.756 W/WindowManager(247):动画重复在太多迭代后中止
01-23 17:14:02.796 I/ActivityManager(247):不再需要 com.sonyericsson.widget.analogclock(pid 4656):隐藏 #16
01-23 17:14:02.806 I/ActivityManager(247): 启动 proc org.videolan.vlc.betav7neon 广播 org.videolan.vlc.betav7neon/.PhoneStateReceiver: pid=5675 uid=10152 gids={3003, 1007, 1015}
01-23 xx flg=0x10000000 cmp=com.android.phone/.SemcInCallScreen(有附加功能)}来自 pid 351
01-23 17:21:03.821 I/ActivityManager(247): 不再需要 com.sonyericsson.idd.agent (pid 4221): 隐藏 #16
01-23 17:21:03.821 I/ActivityManager(247): 不再需要 org.videolan.vlc.betav7neon (pid 5675): hidden #17
01-23 17:21:04.161 I/ActivityManager(247): 启动 proc org.videolan.vlc.betav7neon 广播 org.videolan.vlc.betav7neon/.PhoneStateReceiver: pid=5778 uid=10152 gids={3003, 1007, 1015}
01-23 17:21:04.352 I/TelephonyRegistry(247): notifyDataConnection: state=3 isDataConnectivityPossible=true reason=2GVoiceCallStarted interfaceName=rmnet0 networkType=2
01-23 17:21:04.521 I/ActivityManager(247): 不再需要 com.sonyericsson.androidapp.fbmusiclike (pid 4305): 隐藏 #16
01-23 17:21:05.101 I/ActivityManager(247): 启动 proc com.sonyericsson.idd.agent 广播 com.sonyericsson.idd.agent/.IDDAutoStart: pid=5788 uid=10010 gids={3003, 1015}
01-23 17:21:05.521 I/ActivityManager(247):启动 proc com.sonyericsson.androidapp.fbmusiclike 广播 com.sonyericsson.androidapp.fbmusiclike/.facebook.AvailabilityChangeReceiver:pid=5797 uid=10011 gids={3003}
01-23 17:21:06.021 I/ActivityManager(247): 不再需要 com.sonyericsson.facebook.proxylogin (pid 4358): 隐藏 #16
01-23 17:21:06.021 I/ActivityManager(247): 不再需要 com.sonyericsson.statusswitch (pid 481): hidden #16
01-23 17:21:06.031 W/ActivityManager(247):计划在 5000 毫秒内重新启动崩溃的服务 com.sonyericsson.statusswitch/.UpdateService
01-23 17:21:id=5930 uid=10018 gids={3003, 1015}
01-23 17:27:42.752 W/InputManagerService(247):在非重点客户端 com.android.internal.view.IInputMethodClient$Stub$Proxy@2b3b21e0 上开始输入(uid=10018 pid=5930)
01-23 17:27:46.282 I/ActivityManager(247): 为服务 com.wsandroid.suite/.core.services.BootService 启动 proc com.wsandroid.suite: pid=5952 uid=10126 gids={3003, 1015, 1007}
01-23 17:27:56.292 I/ActivityManager(247): 为服务 com.sonyericsson.updatecenter/.UpdateCenterService 启动 proc com.sonyericsson.updatecenter: pid=5962 uid=10013 gids={3003, 2001, 1015}
01-23 17:28:06.282 I/ActivityManager(247):为服务 com.scoreloop.magicbox/.service.MagicBoxService 启动 proc com.scoreloop.magicbox:pid=5970 uid=10023 gids={3003, 1015}
01-23 17:39:36.512 I/ActivityManager(247):为服务 com.sonyericsson.androidapp.storefront/.service.StoreFrontService 启动 proc com.sonyericsson.androidapp.storefront:pid=5991 uid=10042 gids={3003}
01-23 17:45:26.520 I/TelephonyRegistry(247): notifyDataConnection: state=0 isDataConnectivityPossible=false reason=null interfaceName=null networkType=2
01-23 17:45:26.540 I/TelephonyRegistry(247): notifyDataConnection: state=1 isDataConnectivityPossible=true reason=null interfaceName=null networkType=2
01-23 17:45:26.730 I/ActivityManager(247):启动 proc com.sonyericsson.appshare 用于广播 com.sonyericsson.appshare/.backend.SyncSchedulerReceiver:pid=6008 uid=10138 gids={3003, 1015}
01-23 17:45:32.520 I/TelephonyRegistry(247): notifyDataConnection: state=2 isDataConnectivityPossible=true reason=null interfaceName=rmnet0 networkType=2
01-23 17:47:41.072 I/ActivityManager(247): 为服务 com.google.android.apps.maps/com.google.googlenav.friend.android 启动 proc com.google.android.apps.maps:BackgroundFriendService。背景朋友服务:pid=6044 uid=10050 gids={3003, 1015}
01-23 17:49:22.453 I/ActivityManager(247):不再需要 com.sonyericsson.usbux(pid 315):hiodClient$Stub$Proxy@2b48a9a8
01-23 18:35:18.629 I/ActivityManager(247):开始:Intent { act=android.intent.action.VIEW dat=content://com.google.android.providers.talk/messagesByAcctAndContact/1/saklani。 sanjeev%40gmail.com flg=0x34000000 cmp=com.google.android.talk/.ChatScreen bnds=[0,94][320,158](有附加功能)}来自 pid -1
01-23 18:35:18.699 I/ActivityManager(247):为活动 com.google.android.talk/.ChatScreen 启动 proc com.google.android.talk:pid=6413 uid=10121 gids={3003, 1015,第1006章
01-23 18:35:28.349 W/InputManagerService(247):在非聚焦客户端 com.android.internal.view.IInputMethodClient$Stub$Proxy@2b50a888 上开始输入(uid=10121 pid=6413)
01-23 18:35:29.749 I/ActivityManager(247):开始:Intent { act=android.intent.action.PROVIDER_CHANGED cat=[dashingsanchit@gmail.com] dat=content://gmail-ls/unread/^ i flg=0x4000000 cmp=com.google.android.gm/.ConversationListActivity bnds=[0,94][320,158](有附加功能)} 来自 pid -1
01-23 18:35:29.749 W/ActivityManager(247): startActivity 从非活动上下文中调用;强制 Intent.FLAG_ACTIVITY_NEW_TASK 用于: Intent { act=android.intent.action.PROVIDER_CHANGED cat=[dashingsanchit@gmail.com] dat=content://gmail-ls/unread/^i flg=0x4000000 cmp=com.google.android .gm/.ConversationListActivity bnds=[0,94][320,158](有附加功能)}
01-23 18:35:40.479 com.android.vending 包中的 I/Activin 权限 android.permission.PACKAGE_VERIFICATION_AGENT
01-23 19:13:48.480 W/PackageManager(247): com.android.vending 包中的未知权限 android.permission.MANAGE_USERS
01-23 19:13:48.480 W/PackageManager(247): com.android.vending 包中的未知权限 android.permission.INTERACT_ACROSS_USERS
01-23 19:13:48.510 W/PackageManager(247): com.sonyericsson.retaildemo 包中的未知权限 com.sonyericsson.permission.CUSTOMIZATION
01-23 19:13:48.510 W/PackageManager(247):未授予 android.permission.CLEAR_APP_USER_DATA 对 com.sonyericsson.retaildemo 包的权限(protectionLevel=2 标志=0xbe45)
01-23 19:13:48.510 W/PackageManager(247): com.sonyericsson.androidapp.timescapefeedsplugin 包中的未知权限 com.sonyericsson.extras.liveview.permission.LIVEVIEW_API
01-23 19:13:48.510 W/PackageManager(247): com.sonyericsson.permission.CONTACTS_PICK_CONVERSATIONS_TARGET 包 com.sonyericsson.conversations 中的未知权限
01-23 19:13:48.510 W/PackageManager(247):com.sonyericsson.conversations 包中的未知权限 com.sonyericsson.permission.ACCESS_PROTECTED_CONTACTS
01-23 19:13:48.510 是)},标志=2
01-23 19:15:04.730 E/fb_music_like(6974):不采取行动,无视意图
01-23 19:15:04.73T 释放174K,释放50% 2892K/5767K,外接743K/1036K,暂停27ms
01-23 19:15:16.990 D/dalvikvm(3102):GC_CONCURRENT 释放 461K,46% 释放 3767K/6855K,外部 743K/1036K,暂停 2ms+3ms
01-23 19:15:17.180 D/dalvikvm(5816):GC_CONCURRENT 释放 442K,49% 释放 3119K/6087K,外部 743K/1036K,暂停 1ms+3ms
01-23 19:15:17.630 D/dalvikvm(3278):GC_EXPLICIT 释放 200K,51% 释放 2875K/5767K,外部 743K/1036K,暂停 25ms
01-23
01-23 19:15:22.480 D/dalvikvm(247):GC_EXPLICIT 释放 387K,38% 释放 7506K/11975K,外部 1343K/1943K,暂停 69ms
01-23 19:15:23.390 D/dalvikvm(6907):GC_CONCURRENT 释放 525K,45% 释放 3675K/6599K,外部 1330K/1607K,暂停 3ms+3ms
01-23 19:15:23.580 D/dalvikvm(6907):GC_FOR_MALLOC 释放 1062K,55% 空闲 3089K/6855K,外部 924K/1436K,暂停 54ms

从我的索尼爱立信 Xperia mini pro 发送

4

2 回答 2

3

经过12小时的持续研发,我得到了解决方案。这不仅会显示一天的通话记录,还会显示您手机的整个通话记录。

这是代码

将此方法复制到 java 文件中并在 oncreate() 中调用此方法

private void getCallDetails() {

    StringBuffer sb = new StringBuffer();
    Cursor managedCursor = managedQuery( CallLog.Calls.CONTENT_URI,null, null,null, null);
    int number = managedCursor.getColumnIndex( CallLog.Calls.NUMBER );
    int type = managedCursor.getColumnIndex( CallLog.Calls.TYPE );
    int date = managedCursor.getColumnIndex( CallLog.Calls.DATE);
    int duration = managedCursor.getColumnIndex( CallLog.Calls.DURATION);
    sb.append( "Call Details :");
    while ( managedCursor.moveToNext() ) {
    String phNumber = managedCursor.getString( number );
    String callType = managedCursor.getString( type );
    String callDate = managedCursor.getString( date );
    Date callDayTime = new Date(Long.valueOf(callDate));
    String callDuration = managedCursor.getString( duration );
    String dir = null;
    int dircode = Integer.parseInt( callType );
    switch( dircode ) {
    case CallLog.Calls.OUTGOING_TYPE:
    dir = "OUTGOING";
    break;

    case CallLog.Calls.INCOMING_TYPE:
    dir = "INCOMING";
    break;

    case CallLog.Calls.MISSED_TYPE:
    dir = "MISSED";
    break;
    }
    sb.append( "\nPhone Number:--- "+phNumber +" \nCall Type:--- "+dir+" \nCall Date:--- "+callDayTime+" \nCall duration in sec :--- "+callDuration );
    sb.append("\n----------------------------------");
    }
    managedCursor.close();
    tvcall.setText(sb);
    }

在 Xml 文件中粘贴此代码,使用这样的滚动视图和文本视图

<ScrollView
        android:id="@+id/layoutmain"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/call"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
        </TextView>
    </ScrollView>


采取一个 Textview & 初始化并像这样在 OnCreate() 中调用上述方法


TextView tvcall;
tvcall=(TextView)findViewById(R.id.call);
getCallDetails();

输出是
在此处输入图像描述

于 2013-01-24T08:44:37.783 回答
0

在您的清单中添加此权限

<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
于 2013-03-18T08:12:40.917 回答