phucloi89
phucloi89

Reputation: 39

Translate in Android using Google API

I want to create a translate app in Android,i use Google Translate API,but it has error,please help me for fix it. This is my code

public void onClick(View v) {
        // TODO Auto-generated method stub
        String InputString;
        String OutputString = null;
        InputString = InputText.getText().toString();

        try {

            Translate.setHttpReferrer("http://translate.google.com.vn/");
            OutputString = Translate.DEFAULT.execute(InputString, Language.ENGLISH, Language.VIETNAMESE);    ////////

        } catch (Exception ex) {
            ex.printStackTrace();
            OutputString = "Error";

        }

        OutputText.setText(OutputString);               
    }   

Here is my Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.stthing"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Error in line Translate.setHttpReferrer("http://translate.google.com.vn/");

The method setHttpReferrer(String) is undefined for the type Translate

Upvotes: 1

Views: 3273

Answers (1)

Dilberted
Dilberted

Reputation: 1172

I am not sure if you are aware but Translate API is no longer free. so you would need to set the API key as well..

instead of using

Translate.setHttpReferrer("http://translate.google.com.vn/");

use

GoogleAPI.setHttpReferrer("http://translate.google.com.vn/");
GoogleAPI.setKey(/* Enter your API key here */);

Upvotes: 3

Related Questions