Search code examples
androidcall

Writing in Call history in android phone


I was wondering if there is any way that I can write some numbers into Call History i.e Missed calls. What I want to do is I want when I run my application it will write a number let say that number is 04556433 in the call history and it will be shown as Missed call alert when I will close the application. Any Suggestions?


Solution

  • public static void insertPlaceholderCall(ContentResolver contentResolver, String number)      {
            ContentValues values = new ContentValues();
            values.put(CallLog.Calls.NUMBER, number);
            values.put(CallLog.Calls.DATE, System.currentTimeMillis());
            values.put(CallLog.Calls.DURATION, 0);
            values.put(CallLog.Calls.TYPE, CallLog.Calls.MISSED_TYPE);
            values.put(CallLog.Calls.NEW, 1);
            values.put(CallLog.Calls.CACHED_NAME, "");
            values.put(CallLog.Calls.CACHED_NUMBER_TYPE, 0);
            values.put(CallLog.Calls.CACHED_NUMBER_LABEL, "");
            contentResolver.insert(CallLog.Calls.CONTENT_URI, values);
        }
    

    For this you will need the following permission android:name="android.permission.READ_CONTACTS and android.permission.WRITE_CONTACTS