Android: Automatic update of my app
<p>I am beginner android developer.I wrote some simple app,witch adding to the calendar informations about calls.Now i want to add automatic update,if somebody call me,it automaticly update calendar.</p>

<p>Source code:</p>

<pre><code> DateFormat date = new SimpleDateFormat("dd/MM/yyyy hh:mm");
        String[] projection = new String[] { "_id", "name" };
        ContentValues event = new ContentValues();
        long currentTime = System.currentTimeMillis();

        Cursor callCur = getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI, null, null, null, android.provider.CallLog.Calls.DATE + " DESC");
        Uri calendarsUri = Uri.parse("content://com.android.calendar/calendars");
        Cursor managedCursor = managedQuery(calendarsUri, projection, "selected=1", null, null);

        int typeOfCall = 0;
        String callCachedName = null;
        String callName = null;
        int duration = 0;
        String compareNumbers = null;


        while(callCur.moveToNext()){

        compareNumbers = callCur.getString(callCur.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME));

        int callDateIn = callCur.getColumnIndexOrThrow(android.provider.CallLog.Calls.DATE);
        long callDateLong = new Long(callCur.getLong(callDateIn));

        event.put("calendar_id", 2);

        typeOfCall = callCur.getInt(callCur.getColumnIndex(android.provider.CallLog.Calls.TYPE));
        Log.d(TAG, "Type of Call: " + typeOfCall);

        if (typeOfCall == 1){
            duration = callCur.getInt(callCur.getColumnIndex(android.provider.CallLog.Calls.DURATION));
            Log.d(TAG, "Duration: " + duration);

            if (duration == 0){
                event.put("description", "Number wasn't avaibled"); 
                }
            else{
                event.put("description", "Duration of call was: " + duration);  
            }
            if (compareNumbers == null){
                callName = callCur.getString(callCur.getColumnIndex(android.provider.CallLog.Calls.NUMBER));
                Log.d(TAG, "callName: " + callName);
                event.put("title", "Called to: " + callName);
            }
            else {
                callCachedName = callCur.getString(callCur.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME));
                Log.d(TAG, "cachedName: " + callCachedName);
                event.put("title", "Called to: " + callCachedName);
            }

        }
        if (typeOfCall == 2){
            duration = callCur.getInt(callCur.getColumnIndex(android.provider.CallLog.Calls.DURATION));
            Log.d(TAG, "Duration: " + duration);
            if (duration == 0){
                event.put("description", "Call was interupted");    
                }
            else{
                event.put("description", "Duration of call was: " + duration);  
            }
            if (compareNumbers == null){
                callName = callCur.getString(callCur.getColumnIndex(android.provider.CallLog.Calls.NUMBER));
                Log.d(TAG, "callName: " + callName);
                event.put("title", "Call from : " + callName);
            }
            else {
                callCachedName = callCur.getString(callCur.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME));
                Log.d(TAG, "cachedName: " + callCachedName);
                event.put("title", "Call from : " + callCachedName);
            }

        }
        if (typeOfCall == 3){
             if (compareNumbers == null){
                callName = callCur.getString(callCur.getColumnIndex(android.provider.CallLog.Calls.NUMBER));
                Log.d(TAG, "callName: " + callName);
                event.put("title", "Called to: " + callName);
             }
             else {
                callCachedName = callCur.getString(callCur.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME));
                Log.d(TAG, "cachedName: " + callCachedName);
                event.put("title", "Called to: " + callCachedName);
             }
             if (compareNumbers == null){
                callName = callCur.getString(callCur.getColumnIndex(android.provider.CallLog.Calls.NUMBER));
                Log.d(TAG, "callName: " + callName);
                event.put("title", "Call from : " + callName);
             }
             else {
                callCachedName = callCur.getString(callCur.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME));
                Log.d(TAG, "cachedName: " + callCachedName);
                event.put("title", "Call from : " + callCachedName);
             }


        }

        //event.put("eventLocation", "New Yorks");
        event.put("dtstart", callDateLong );


       Uri eventsUri = Uri.parse("content://com.android.calendar/events");
       Uri calUri = getContentResolver().insert(eventsUri, event);

        }
    }
}
</code></pre>
