Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

import android.widget.Toast;

public class Main {
    public static void callGoogleTranslateApps(Context context, String word, String toLang) {
        try {
            Intent i = new Intent();

            i.setAction(Intent.ACTION_VIEW);

            i.putExtra("key_text_input", word);
            i.putExtra("key_text_output", "");
            i.putExtra("key_language_from", "en");
            i.putExtra("key_language_to", "vi");
            i.putExtra("key_suggest_translation", "");
            i.putExtra("key_from_floating_window", false);

            i.setComponent(new ComponentName("com.google.android.apps.translate",
                    "com.google.android.apps.translate.TranslateActivity"));
            context.startActivity(i);
        } catch (ActivityNotFoundException ex) {
            Toast.makeText(context, "Google translate app is not installed", Toast.LENGTH_SHORT).show();
            ex.printStackTrace();
        }
    }
}