Chaythanya nair Chaythanya nair - 17 days ago 6
Java Question

Access Google Translate App through intents in android

I am developing an Android application where I am invoking the Google Translate app via Intents. The procedure described here was really helpful but I cannot figure out why my app crashes saying "No Activity found to handle Intent".

Thanks in Advance!

Here is my code,

public void translate()
{
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "hello");
intent.putExtra("key_text_input", "hello");
intent.putExtra("key_text_output", "");
intent.putExtra("key_language_from", "en");
intent.putExtra("key_language_to", "mal");
intent.putExtra("key_suggest_translation", "");
intent.putExtra("key_from_floating_window", false);
new ComponentName(
"com.google.android.apps.translate",
"com.google.android.apps.translate.HomeActivity");
startActivity(intent);

}


And this is what my logcat shows

04-20 07:29:01.647: E/AndroidRuntime(31465): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND flg=0x1 (has clip) (has extras) }
04-20 07:29:01.647: E/AndroidRuntime(31465): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
04-20 07:29:01.647: E/AndroidRuntime(31465): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1423)
04-20 07:29:01.647: E/AndroidRuntime(31465): at android.app.Activity.startActivityForResult(Activity.java:3388)
04-20 07:29:01.647: E/AndroidRuntime(31465): at android.app.Activity.startActivityForResult(Activity.java:3349)
04-20 07:29:01.647: E/AndroidRuntime(31465): at android.app.Activity.startActivity(Activity.java:3584)
04-20 07:29:01.647: E/AndroidRuntime(31465): at android.app.Activity.startActivity(Activity.java:3552)
04-20 07:29:01.647: E/AndroidRuntime(31465): at com.example.arch.vaani.ocr.FinalActivity.translate(FinalActivity.java:122)
04-20 07:29:01.647: E/AndroidRuntime(31465): at com.example.arch.vaani.ocr.FinalActivity$1.onClick(FinalActivity.java:101)
04-20 07:29:01.647: E/AndroidRuntime(31465): at android.view.View.performClick(View.java:4212)
04-20 07:29:01.647: E/AndroidRuntime(31465): at android.view.View$PerformClick.run(View.java:17476)
04-20 07:29:01.647: E/AndroidRuntime(31465): at android.os.Handler.handleCallback(Handler.java:800)
04-20 07:29:01.647: E/AndroidRuntime(31465): at android.os.Handler.dispatchMessage(Handler.java:100)
04-20 07:29:01.647: E/AndroidRuntime(31465): at android.os.Looper.loop(Looper.java:194)
04-20 07:29:01.647: E/AndroidRuntime(31465): at android.app.ActivityThread.main(ActivityThread.java:5371)
04-20 07:29:01.647: E/AndroidRuntime(31465): at java.lang.reflect.Method.invokeNative(Native Method)
04-20 07:29:01.647: E/AndroidRuntime(31465): at java.lang.reflect.Method.invoke(Method.java:525)
04-20 07:29:01.647: E/AndroidRuntime(31465): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
04-20 07:29:01.647: E/AndroidRuntime(31465): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
04-20 07:29:01.647: E/AndroidRuntime(31465): at dalvik.system.NativeStart.main(Native Method)

Answer

I tried the code with a Google Translate App and it is not working. You may have to use the Translate API which is a paid service.

Comments