0
我正在創建一個小部件來訪問存儲在谷歌日曆中的事件。 目標:機器人2.1卡在Android的gdata日曆分析異常
我已經包括以下外部罐:
谷歌-收集-1.0-rc1.jar jsr305.jar
GDATA個歷2.0.jar,
GDATA個曆元2.0.jar,
GDATA,客戶1.0.jar,
gdat一個客戶端 - 元1.0.jar,
GDATA核-1.0.jar
我得到以下異常:
com.google.gdata.util.ParseException : org.xml.sax
這裏是我的代碼:HelloWidget.java
package de.thesmile.android.widget2;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.util.Log;
import android.widget.RemoteViews;
import com.google.gdata.client.calendar.*;
import com.google.gdata.data.*;
import de.thesmile.android.widget2.R;
public class HelloWidget extends AppWidgetProvider {
int number =0;
public String gooleres()
{
String result=new String("Unable to login into your account");
// Create a CalenderService and authenticate
try
{
URL feedUrl = new URL("https://www.google.com/calendar/feeds/default/private/full");
CalendarQuery myQuery = new CalendarQuery(feedUrl);
myQuery.setMinimumStartTime(DateTime.parseDateTime("2011-03-01T00:00:00"));
myQuery.setMaximumStartTime(DateTime.parseDateTime("2011-03-06T23:59:59"));
CalendarService myService = new CalendarService("wqewq");
myService.setUserCredentials("[email protected]", "XXXXXX");
//Send the request and receive the response:
Feed resultFeed = myService.query(myQuery, Feed.class);
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
Entry entry = resultFeed.getEntries().get(i);
result= entry.getTitle().getPlainText().toString();
}
}
catch(Exception e)
{
result="Exception raised "+e.toString();
}
return result;
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
for (int appWidgetId : appWidgetIds) {
RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.main);
views.setTextViewText(R.id.widget_textview, gooleres());
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}
該代碼似乎是正確的,因爲當我試圖把相同的代碼作爲簡單的java文件,那麼我確實得到輸出.. 我創建了簡單的java文件看起來是這樣的,它給適當的輸出..
public static void main(String[] args) {
// TODO Auto-generated method stub
// Create a CalenderService and authenticate
try
{
URL feedUrl = new URL("https://www.google.com/calendar/feeds/default/private/full");
CalendarQuery myQuery = new CalendarQuery(feedUrl);
myQuery.setMinimumStartTime(DateTime.parseDateTime("2011-03-01T00:00:00"));
myQuery.setMaximumStartTime(DateTime.parseDateTime("2011-03-08T23:59:59"));
CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials("[email protected]", "ytrfvgb$");
// Send the request and receive the response:
Feed resultFeed = myService.query(myQuery, Feed.class);
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
Entry entry = resultFeed.getEntries().get(i);
System.out.println(Integer.toString(i)+entry.getTitle().getPlainText().toString());
}
}
catch (Exception e) {
// TODO: handle exception
System.out.println(e.toString());
}
}