gpt4 book ai didi

android - 从 WebView 添加日历事件

转载 作者:行者123 更新时间:2023-11-30 01:01:17 24 4
gpt4 key购买 nike

我正在关注 this tutorial使从 WebView 添加日历事件成为可能。我知道该方法正在使用 shouldOverrideUrlLoading 作为 url date:

public boolean shouldOverrideUrlLoading (WebView view, String url) {

if (url.startsWith("date:")) {

Log.d(this.getClass().getCanonicalName(),url);

Calendar beginCal = Calendar.getInstance();

Calendar endCal = Calendar.getInstance();

Date beginDate = new Date(0, 0, 0);

Date endDate = new Date(0, 0, 0);

String parsed = url.substring(5);

String[] components = parsed.split(",");

beginDate.setMonth(Integer.parseInt(components[0]));

beginDate.setDate(Integer.parseInt(components[1]));

beginDate.setYear(Integer.parseInt(components[2]));

beginCal.setTime(beginDate);

endDate.setMonth(Integer.parseInt(components[3]));

endDate.setDate(Integer.parseInt(components[4]));

endDate.setYear(Integer.parseInt(components[5]));

endCal.setTime(endDate);

calendarevent(beginCal, endCal, components[6]);

return true;

}

return false;

}

});

但是,我无法理解我应该输入的 date: url 的格式:

<a href='date:beginmonth, beginday, beginyear, 
endmonth, endday, endyear, My Event Description'>
My event link</a>

比如我在2016年9月15日有一个 Activity ,所以我把url变成了:

<a href='date:09,15,2016,09,15,2016, My Event Description'>
My event link</a>

我弄错了日期。日期变为 2011 年 5 月 11 日。我犯了什么错误?

最佳答案

我自己解决了这个问题。该错误的发生可能是由于根据 documentation 使用了已弃用的 Date .更改为 Calendar.set,现在可以使用了。

Calendar beginCal = Calendar.getInstance();
Calendar endCal = Calendar.getInstance();

String parsed = url.substring(5);
String[] components = parsed.split(",");
int month = Integer.parseInt(components[0])-1;
int day = Integer.parseInt(components[1]);
int year = Integer.parseInt(components[2]);
beginCal.set(year, month, day);

int monthend = Integer.parseInt(components[3])-1;
int dayend = Integer.parseInt(components[4]);
int yearend = Integer.parseInt(components[5]);

endCal.set(yearend, monthend, dayend);
calendarevent(beginCal, endCal, components[6]);

关于android - 从 WebView 添加日历事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39349243/

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