How can I fix the “Error connecting with login URI

2020-04-20 17:04发布

I use the following code in Java. It works well and it adds events into Google Calendar. But in Android it gives the Exception Error connecting with login URI. Can anyone help me to solve this?

CalendarService myService = new CalendarService("calendarTest");
String userName = "mytest.test@gmail.com";
String userPassword = "xxxxxxx";

// Create the necessary URL objects.
try {
    metafeedUrl = new URL(METAFEED_URL_BASE + userName);
    eventFeedUrl = new URL(METAFEED_URL_BASE + userName
        + EVENT_FEED_URL_SUFFIX);
} catch (MalformedURLException e) {
    // Bad URL
    strbuf.append(e.getMessage());
    System.err.println("Uh oh - you've got an invalid URL.");
    e.printStackTrace();
    return;
}

try
{
    myService.setUserCredentials(userName, userPassword);
    // Demonstrate creating a single-occurrence event.
    CalendarEventEntry singleEvent = createSingleEvent(myService,"Event Title", "Event Description "); 
    System.out.println("Successfully created event " +singleEvent.getTitle().getPlainText() );

    // Demonstrate creating a quick add event.
    CalendarEventEntry quickAddEvent = createQuickAddEvent(myService,"Tennis with me June 22 3pm-3:30pm");
    System.out.println("Successfully created quick add event "       + quickAddEvent.getTitle().getPlainText());

}
// catch.......

1条回答
Emotional °昔
2楼-- · 2020-04-20 17:45

This needs internet-access to add something to the calendar, right?

So you need to give your app the permission for internet access. Try adding this right before the closing tag of AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
查看更多
登录 后发表回答