How can I use Google Translate API and translate text in an android app? I tried this:
http://code.google.com/p/google-api-translate-java/
but it doesn't work. I have an Api Key too. My code is(according to official example):
GoogleAPI.setHttpReferrer("http://mysite.com");
GoogleAPI.setKey("My Key");
String translatedText = Translate.DEFAULT.execute("Bonjour le monde", Language.FRENCH, Language.ENGLISH);
I put this code in my main Activity but I get an error: "Unhandled exception type GoogleAPIException" and there is a suggestion to fix that error: "Surrond with Try/Catch". But when I changed code to:
try {
String translatedText = Translate.DEFAULT.execute("Bonjour le monde", Language.FRENCH, Language.ENGLISH);
} catch (GoogleAPIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
my code runs correctly but I can't get any response (translated text). I set this permission too: <uses-permission android:name="android.permission.INTERNET"/>
Where is my mistake?