Friday, May 18, 2012

Using Google Translate API In Android

In this tutorial we are going to know how we can use google translate API in Android

At first download google-api-translate-java-0.95.jar here 

Import that JAR file to android buid Path (Right-click project->Properties->Java Build Path-> Libraries->Add External JARS.)

The xml file


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""

The JAVA file

package com.myapps.translate;

import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;


public class Translator extends Activity {
    /** Called when the activity is first created. */
String translatedText;

    public void onCreate(Bundle savedInstanceState) {
        TextView tv = new TextView(this);
        Translate t = new Translate();
        try {
translatedText = t.execute("Bonjour le monde", Language.FRENCH, Language.ENGLISH);

        } catch (Exception e) {
// TODO Auto-generated catch block

        Toast.makeText(this, translatedText, Toast.LENGTH_SHORT).show();