gpt4 book ai didi

android - 在 ICE CREAM SANDWICH 中运行应用程序时发生崩溃

转载 作者:行者123 更新时间:2023-11-29 18:13:25 24 4
gpt4 key购买 nike

我创建了一个将事件存储在设备日历中的应用程序,并且可以正常工作。但是当我尝试在 ICE CREAM SANDWICH 中做同样的事情时,应用程序崩溃了。为什么会这样?谁能帮我解决这个问题?我用来在设备日历中保存事件的代码如下所示。还包括崩溃日志。

将事件保存到设备日历的代码

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);
}

日志输出

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

最佳答案

我也遇到了这个问题,现在解决了。你想要在 ICE CREAM SANDWICH 上面正常工作的代码,你需要设置 eventTimezone 的值。好吧,只需要添加像

这样的代码
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);

关于android - 在 ICE CREAM SANDWICH 中运行应用程序时发生崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9533757/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com