I need to get the call number as soon as he makes the call from his android mobile and then when the call ends then i need the duration of the call.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Create One broadcast receiver and write following in your receiver onReceive()
method
this receiver return last record of your call but make some time delay so it can return current record.
Cursor c=context.getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI,null, null, null,android.provider.CallLog.Calls.DATE + " DESC");
int numberColumn = c.getColumnIndex(android.provider.CallLog.Calls.NUMBER);
int dateColumn = c.getColumnIndex(
android.provider.CallLog.Calls.DATE);
// type can be: Incoming, Outgoing or Missed
int typeColumn = c.getColumnIndex(android.provider.CallLog.Calls.TYPE);
int DurationColumn = c.getColumnIndex(android.provider.CallLog.Calls.DURATION);
Write following Your mainfest file
<receiver android:name="Your Receiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
In onRecieve put this
Bundle bundle = intent.getExtras();
Set<String> keys = bundle.keySet();
for (String key : keys) {
Log.i("MYAPP##", key + "="+ bundle.getString(key));
if(bundle.getString(key).equals("IDLE"))
{
}
}