android谷歌日历..申请人关闭

时间:2011-03-06 09:24:01

标签: android google-calendar-api

我正在尝试使用gdata访问Google日历。但应用程序关闭:( 我已经将gdata-client-1.0.jar添加为外部jar。

这是我的文件: rrr.java     包caleda.qwe;

import java.net.URL;

import com.google.gdata.client.calendar.CalendarService;
import com.google.gdata.data.calendar.CalendarEntry;
import com.google.gdata.data.calendar.CalendarFeed;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class rrr extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        String res="not proper";
     // Create a CalenderService and authenticate
        CalendarService myService = new CalendarService("calendar");
        try{
        myService.setUserCredentials("sunnycool333", "XXXXX");

        // Send the request and print the response
        URL feedUrl = new URL("https://www.google.com/calendar/feeds/default/owncalendars/full");
        CalendarFeed resultFeed = myService.getFeed(feedUrl, CalendarFeed.class);
      //  System.out.println("Calendars you own:");
       // System.out.println();
        for (int i = 0; i < resultFeed.getEntries().size(); i++) {
          CalendarEntry entry = resultFeed.getEntries().get(i);
        //  System.out.println("\t" + entry.getTitle().getPlainText());
          res=entry.getTitle().getPlainText();
        }
        }
        catch (Exception e) {
            // TODO: handle exception
            //System.out.println("not working");
            res=e.toString();
        }

        TextView view = (TextView)findViewById(R.id.TextView01);
        view.setText(res);
    }
}

main.xml中

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
<TextView android:text="@+id/TextView01" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>

applicationmanifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="caleda.qwe"
      android:versionCode="1"
      android:versionName="1.0">
      <uses-permission android:name="android.permission.INTERNET" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".rrr"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>


</manifest> 

有人可以帮我指出我的错误。

2 个答案:

答案 0 :(得分:1)

您的活动可能无法使用Application Not Responding对话框,因为您正在UI线程上进行网络访问。

尝试使用AsyncTask

This question有一些关于AsyncTask的示例代码和链接。

答案 1 :(得分:0)

非常感谢大家......

如果我们再添加两个文件作为外部jar文件,问题就会解决..

这两个文件位于gdata客户端src的“deps”文件夹中。 命名:google-collect-1.0-rc1.jar&amp; jsr305.jar