如何将自定义网址解析为日历活动?

时间:2014-10-23 19:32:13

标签: android parsing url calendar jsoup

我想要做的是,使用我的这个自定义网址

(mlevents://add/event?day=8&month=10&year=2014&timestring=12:00 PM - 12:30 PM &hourS=12&minuteS=00&hourE=12&minuteE=30&title=Filene 101: Think. Do. Change. | Webinar&timezone=CST)

能够解析并保存为将存储到Google日历的日历事件,我没有运气,我在我的manifest.xml中设置了自定义方案,但仍然没有运气。我如何设置它以使其正常工作?

1 个答案:

答案 0 :(得分:1)

您需要使用String.split方法,该方法采用正则表达式模式,具体取决于您需要更改模式的内容 - 但要将字符串拆分为“&”然后对于数组中的每个字符串使用“=”,你会这样做:这是一个完整的代码:tru

public class Event {
String[] myStringArr;

int day;
int month;
int year;
String timeString;
int hourS;
int minuteS;
int hourE;
int minuteE;
String title;
String timezone;

public int getDay() {
    return Integer.parseInt(myStringArr[0].split("=")[1]);
}

public int getMonth() {
    return Integer.parseInt(myStringArr[1].split("=")[1]);
}

public int getYear() {
    return Integer.parseInt(myStringArr[2].split("=")[1]);
}

public String getTimeString() {
    return myStringArr[3].split("=")[1];
}

public int getHourS() {
    return Integer.parseInt(myStringArr[4].split("=")[1]);
}

public int getMinuteS() {
    return Integer.parseInt(myStringArr[5].split("=")[1]);
}

public int getHourE() {
    return Integer.parseInt(myStringArr[6].split("=")[1]);
}

public int getMinuteE() {
    return Integer.parseInt(myStringArr[7].split("=")[1]);
}

public String getTitle() {
    return myStringArr[8].split("=")[1];
}

public String getTimezone() {
    return myStringArr[9].split("=")[1];
}

public Event(String[] myStringArr) {
    super();
    this.myStringArr = myStringArr;
}

}

在您的活动中:

    String customUrl = "(mlevents://add/event?day=8&month=10&year=2014&timestring=12:00 PM - 12:30 PM &hourS=12&minuteS=00&hourE=12&minuteE=30&title=Filene 101: Think. Do. Change. | Webinar&timezone=CST)";
    final String[] myStringArr = customUrl.split("&");
    Event event = new Event(myStringArr);   

    System.out.println(event.getDay()); // -> return 8 : the day 
    System.out.println(event.getTitle()); // return Filene 101: Think. Do. Change. | Webinar 

   // etc.. your variable event contains all data from your url , 
  // to get an info just call : event.getWhatYouWant();