Мое Java-приложение может подключаться и извлекать мои контакты Gmail, но приложение Android выдает исключение «Ошибка соединения с URI входа в систему».
Вот код из обоих приложений.Я пробовал приложение для Android на эмуляторе и телефоне.В обоих я получаю одинаковую ошибку.Я могу открывать страницы в веб-браузере в обоих (я имел в виду, у меня есть доступ в интернет).Пожалуйста, сообщите.
//Java Application Code
public static void main(String[] args) throws ServiceException, IOException {
ContactsService service;
URL feedUrl;
ContactFeed resultFeed;
String url = "https://www.google.com/m8/feeds/" + "contacts/"
+ "username@gmail.com" + "/thin";
System.err.println("This is the url:" + url);
try {
feedUrl = new URL(url);
service = new ContactsService("Google-contactsExampleApp-3");
service.setUserCredentials("username@gmail.com", "password");
resultFeed = service.getFeed(feedUrl, ContactFeed.class);
for (ContactEntry entry : resultFeed.getEntries()) {
if (entry.getTitle() != null) {
System.err.println("Contact name: "
+ entry.getTitle().getPlainText());
} else {
System.err.println("Contact has no name");
}
}
} catch (Exception e) {
System.err.println("Exception: " + e.getMessage());
}
}
//Android Application Code
public void onClick(View arg0) {
ContactsService service;
URL feedUrl;
ContactFeed resultFeed;
String url = "https://www.google.com/m8/feeds/" + "contacts/"
+ "username@gmail.com" + "/thin";
System.err.println("This is the url:" + url);
try {
feedUrl = new URL(url);
service = new ContactsService("Google-contactsExampleApp-3");
service.setUserCredentials("username@gmail.com", "password");
resultFeed = service.getFeed(feedUrl, ContactFeed.class);
for (ContactEntry entry : resultFeed.getEntries()) {
if (entry.getTitle() != null) {
Toast.makeText(getApplicationContext(),
"Contact name: " + entry.getTitle().getPlainText(),
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(),
"Contact has no name", Toast.LENGTH_SHORT).show();
}
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"Exception: " + e.getMessage(), Toast.LENGTH_SHORT).show();
System.out.println("**** Exception: " + e.getMessage());
//Exception: Error connecting with login URI
}
}
}