Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Getting_Call_log_Service extends Service {
- //variables of getting call logs
- private String ph_number;
- private String temp_name;
- private String real_name;
- private String call_type;
- private String dir;
- private String call_date;
- private String call_duration;
- private Date call_day_time;
- private SQLite_database_helper_class myDb;
- public class callsThread implements Runnable{
- callsThread(){}
- @Override
- public void run() {
- myDb=new SQLite_database_helper_class(getApplicationContext());
- //codes of extracting call logs
- Cursor cursor = getContentResolver().query(CallLog.Calls.CONTENT_URI,
- null,null,null,null);
- int number=cursor.getColumnIndex(CallLog.Calls.NUMBER);//to get the index of phoneNumber column
- int name = cursor.getColumnIndex(CallLog.Calls.CACHED_NAME);//to get the index of contact name column
- int type = cursor.getColumnIndex(CallLog.Calls.TYPE);//to get the call type index
- int callDate = cursor.getColumnIndex(CallLog.Calls.DATE);//to get the date of calling
- int callDuration = cursor.getColumnIndex(CallLog.Calls.DURATION);//to get the duration of calling
- cursor.moveToFirst();
- do {
- //extracting values from phone history
- ph_number=cursor.getString(number);
- temp_name=cursor.getString(name);
- if (temp_name==null){
- real_name="Annonymous caller!";
- }else {
- real_name=temp_name;
- }
- call_type=cursor.getString(type);
- int dir_code=Integer.parseInt(call_type);
- switch (dir_code) {
- case CallLog.Calls.INCOMING_TYPE:
- dir = "INCOMING CALL";
- break;
- case CallLog.Calls.OUTGOING_TYPE:
- dir = "OUTGOING CALL";
- break;
- case CallLog.Calls.MISSED_TYPE:
- dir = "MISSED CALL";
- break;
- case CallLog.Calls.REJECTED_TYPE:
- dir = "REJECTED CALL";
- break;
- case CallLog.Calls.ANSWERED_EXTERNALLY_TYPE:
- dir = "ANSWERED EXTERNALLY";
- break;
- case CallLog.Calls.BLOCKED_TYPE:
- dir = "BLOCKED NUMBER";
- break;
- case CallLog.Calls.VOICEMAIL_TYPE:
- dir = "VOICEMAIL";
- break;
- }
- call_date=cursor.getString(callDate);
- call_day_time=new Date(Long.valueOf(call_date));
- call_duration=cursor.getString(callDuration);
- //end of extraction
- myDb.saving_call_logs(ph_number,real_name,dir,
- call_day_time.toString(), call_duration);
- }while (cursor.moveToNext());
- cursor.close();
- }
- }
- public void calls_fromPhone(){
- Thread callThread=new Thread(new callsThread());
- callThread.start();
- }
Add Comment
Please, Sign In to add comment