2

是否可以获取 Android 与特定联系人相关的通话、短信和聊天的统计信息?这个统计数据是否存储在某个地方?如果没有,是否有任何方法可以使用 Android SDK 获取和存储该统计信息?使用 Android NDK?Android系统是否允许以某种方式挂钩短信和聊天事件?

4

1 回答 1

1

1. 来电和去电,可通过BroadCastReceivers手动收听。

显现:

<receiver android:name="IncomingCallReceiver" >
    <intent-filter>
        <action android:name="android.intent.action.PHONE_STATE" />
    </intent-filter>
</receiver>
<receiver android:name="OutgoingCallReceiver" >
    <intent-filter>
        <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
    </intent-filter>
</receiver>

广播接收器:

public class IncomingCallReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle extras = intent.getExtras();
        if(extras == null)
            return;

        String callState = extras.getString(TelephonyManager.EXTRA_STATE);

        // ringing state
        if(callState.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING)){
            String incomingNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
            Toast.makeText(context,"Incoming number: " + incomingNumber,Toast.LENGTH_LONG).show();
        }
    }
}

public class OutgoingCallReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle extras = intent.getExtras();
        if(extras == null)
            return;
        // caller
        String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        // Toast megjelenitese
        Toast.makeText(context,"Outgoing number: "+phoneNumber, Toast.LENGTH_LONG).show();
    }
}

2.您还可以创建一个光标到通话记录,然后您可以遍历该光标。

String[] strFields = { android.provider.CallLog.Calls._ID,
        android.provider.CallLog.Calls.NUMBER,
        android.provider.CallLog.Calls.CACHED_NAME};
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
final Cursor cursorCall = getContentResolver().query(
        android.provider.CallLog.Calls.CONTENT_URI, strFields,
        null, null, strOrder);

3. 对于 SMS 你也可以创建BroadcastReceivers,或者你也可以创建一个ContentObserver到特定的内容。也许聊天被保存到您可以与ContentObserver挂钩的地方。

于 2013-01-24T08:24:15.267 回答