Is it possible to get Android's statistics of calls, sms and chats related to specific contact? Is this statistic stored somewhere? If not is there any method to get and store that statistics using Android SDK? Using Android NDK? Does Android system allows to hook a SMS and Chats events somehow?
Asked
Active
Viewed 419 times
2
-
How would you access the chat data for a contact? using gmail id of the contact? For sms and call logs you can refer this [callmeter](https://github.com/felixb/callmeter) library. – Supreethks Jan 24 '13 at 08:04
-
I do not access the chat data for now. How can I do it? For now I have only a Chat ID from Contacts database. – Ekaterina Ivanova iceja.net Jan 24 '13 at 08:06
-
for a particular contact , you need to fire a query in content resolver for text and calls. – Jambaaz Jan 24 '13 at 08:08
-
What kind of query? Which table in contacts database or Class should I use? – Ekaterina Ivanova iceja.net Jan 24 '13 at 08:11
-
You need not access the tables directly (infact you cannot access database of other applications). There is a concept called [content provider](http://developer.android.com/guide/topics/providers/content-providers.html) in android which enables data transfer in a RESTful way between apps. Check this out. You can get contacts from [contacts provider](http://developer.android.com/guide/topics/providers/contacts-provider.html) – Supreethks Jan 24 '13 at 08:15
-
To access the sms data you can use sms provider, as [explained here](http://stackoverflow.com/a/902692/1186983). – Supreethks Jan 24 '13 at 08:21
1 Answers
1
1. for incoming and outgoing calls, you can collect it manually via BroadCastReceivers.
Manifest:
<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>
BroacastReceivers:
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. You can also create a cursor to Call Log and after you can iterate over this cursor.
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. For SMS you can also create BroadcastReceivers, or you can also create a ContentObserver to the specific content. Maybe the chat is saved to a place to which you can hook with a ContentObserver.

peekler
- 330
- 2
- 10