AndroidDev
AndroidDev

Reputation: 4559

Crash Occur while running app in ICE CREAM SANDWICH

I have created an app that stores events in the device calendar, and it works. But when I try to do the same thing in ICE CREAM SANDWICH it crashes the app. Why does this happen? Can anyone help me solve this? The code I have used to save events in the device calendar is shown below. The log for the crash is included also.

Code for saving events to device calendar

public boolean setAlertOnDevice(Context c)
{                   
Resources res = c.getResources();

Uri EVENTS_URI = Uri.parse("content://com.android.calendar/" + "events");

Uri REMINDERS_URI = Uri.parse("content://com.android.calendar/" + "reminders");

    ContentResolver cr = c.getContentResolver();

Date dtStartDate = getStartDate();  

Calendar cal = Calendar.getInstance();

cal.setTime(dtStartDate);
cal.add(Calendar.DATE, m_iStart);

cal.set(Calendar.HOUR_OF_DAY, 8);  
cal.set(Calendar.MINUTE, DEFAULT_TIME_OF_DATE);     
cal.set(Calendar.SECOND, DEFAULT_TIME_OF_DATE); 
cal.set(Calendar.MILLISECOND, DEFAULT_TIME_OF_DATE);

String str = m_reminderText + res.getString(R.string.alert_start);                                          
m_strDescription = res.getString(R.string.alert_start_msg);

ContentValues values = new ContentValues();
values.put("calendar_id", 1);
values.put("title", str);
values.put("description", m_strDescription);                    
values.put("dtstart", cal.getTimeInMillis()); 
values.put("dtend", cal.getTimeInMillis()); 
values.put("hasAlarm", 1);
Uri event = cr.insert(EVENTS_URI, values);

m_calendarEvents[m_calendarEventCount] = event;
m_calendarEventCount = m_calendarEventCount + 1;

values = new ContentValues();
values.put("event_id", Long.parseLong(event.getLastPathSegment()));
values.put("method", 1);
values.put("minutes", 10);
cr.insert(REMINDERS_URI, values);
}

Log output

03-02 18:28:35.836: E/AndroidRuntime(1362): FATAL EXCEPTION: main
03-02 18:28:35.836: E/AndroidRuntime(1362): java.lang.RuntimeException: Unable to pause          activity {in.plackal.lovecyclesfree/in.plackal.lovecyclesfree.ActivityManager}: java.lang.IllegalArgumentException: Event values must include an eventTimezone
03-02 18:28:35.836: E/AndroidRuntime(1362):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2706)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2662)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2640)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at android.app.ActivityThread.access$800(ActivityThread.java:123)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at  android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at android.os.Looper.loop(Looper.java:137)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at android.app.ActivityThread.main(ActivityThread.java:4424)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at java.lang.reflect.Method.invokeNative(Native Method)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at java.lang.reflect.Method.invoke(Method.java:511)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at dalvik.system.NativeStart.main(Native Method)
03-02 18:28:35.836: E/AndroidRuntime(1362): Caused by: java.lang.IllegalArgumentException: Event values must include an eventTimezone
03-02 18:28:35.836: E/AndroidRuntime(1362):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:165)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at android.content.ContentProviderProxy.insert(ContentProviderNative.java:415)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at android.content.ContentResolver.insert(ContentResolver.java:730)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at in.plackal.lovecyclesfree.CycleManager.setAlertOnDevice(CycleManager.java:1083)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at in.plackal.lovecyclesfree.ActivityManager.onPause(ActivityManager.java:83)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at android.app.Activity.performPause(Activity.java:4563)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1195)
03-02 18:28:35.836: E/AndroidRuntime(1362):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2693)
03-02 18:28:35.836: E/AndroidRuntime(1362):     ... 12 more

Upvotes: 1

Views: 2079

Answers (2)

dfjx
dfjx

Reputation: 21

I also meet this problem and now I solve it. The code you want to work fine above ICE CREAM SANDWICH ,you need to set the values of eventTimezone. Well , just need to add the code like

ContentValues values = new ContentValues();
values.put("calendar_id", 1);
values.put("title", str);
values.put("description", m_strDescription);                    
values.put("dtstart", cal.getTimeInMillis()); 
values.put("dtend", cal.getTimeInMillis()); 
values.put("hasAlarm", 1);

values.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());  //add this row

Uri event = cr.insert(EVENTS_URI, values);

Upvotes: 2

Calvin
Calvin

Reputation: 450

alextsc is correct. You're using undocumented APIs here, which are unsupported and broken for Ice Cream Sandwich. Read that blog post he linked to, and then look into using the CalendarContract API to make Ice Cream Sandwich work for you.

Upvotes: 1

Related Questions