1

I am developing an android application in which i need to give some features of calendar like adding events and displaying events , There is no problem in insertion for that i am using the following code

              Date date = new Date();
        
        System.out.println("dateselected is    " + dateselected);
        try {
 
            date = new SimpleDateFormat("yyyy-MM-dd").parse(dateselected);
        } catch (java.text.ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        startTime = date.getTime();
        
        System.out.println("startTime is    " + startTime);
                
        Calendar cal = Calendar.getInstance();       
        Intent intent = new Intent(Intent.ACTION_EDIT);  
        intent.setType("vnd.android.cursor.item/event");
        intent.putExtra(" THE TESTING EVENT ");
        intent.putExtra("beginTime", startTime);
        
        intent.putExtra("endTime", startTime+60*60*1000);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        finish();
        startActivityForResult(intent,0);

Displaying event in this way

intent.setData(Uri.parse("content://com.android.calendar/events/" + 
                 
                    String.valueOf(eventid[pos])));
            
            System.out.println(" >8 "); 
            //Android 2.1 and below.
            //intent.setData(Uri.parse("content://calendar/events/" + String.valueOf(calendarEventID)));    
        
            
            startActivity(intent);

but the problem is that no matter which date i selected and whatever the event id is it shows only one date and time ,

5:30 am , 1 January 1970

though the event title is correct

which i am testing on samsung galaxy pop android 2.2.1

What should i do to remove this error

Community
  • 1
  • 1
Avi Kumar
  • 4,403
  • 8
  • 36
  • 67
  • Where does dateselected come from? – gutiory Apr 26 '12 at 07:17
  • it comes from previous activity which i receive like dateselected = getIntent().getStringExtra("date"); and is like "DATE IS HERE CHECK = " 2012-05-16 – Avi Kumar Apr 26 '12 at 07:22
  • It's weird, because 1 Jaunary 1970 is the date by defalut when you do a new Date(). It seems that maybe SimpleDateFormat is not working properly. Have you check with the debugger the value of dateselect before calling parse method and the value of date after? – gutiory Apr 26 '12 at 08:05
  • @gutiory dateselect has got the right date i printed that in logcat and , when i insert the event in calendar the start date and end date of the event in calendar is right – Avi Kumar Apr 27 '12 at 10:18

1 Answers1

0

I Have got the solution for this question , from here

How to using intents to view calendar data?

and used the following code just passed the extra intent to display the calendar events with the selected date.

intent.putExtra("beginTime", beginMilliTS);
intent.putExtra("endTime", endMilliTS);
Community
  • 1
  • 1
Avi Kumar
  • 4,403
  • 8
  • 36
  • 67