我在 Java 中使用以下代码。它运行良好,并将事件添加到 Google 日历中。但在 Android 中,它会给出异常 Error connecting with login URI
。谁能帮我解决这个问题?
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.......
最佳答案
这需要互联网访问才能向日历添加内容,对吗?
所以你需要给你的应用程序访问互联网的权限。尝试在 AndroidManifest.xml 的结束标记之前添加:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
关于android - 如何修复向 Google 日历添加事件时出现的 "Error connecting with login URI"异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3069757/