Android Question How to launch Google.Translate offline version?

johnmie

Active Member
Licensed User
Longtime User
For an instant translation I use google.translate in a webview and the user has to click on the COPY button if he is happy with the translation.

That works fine if he is online, but even after downloading an offline version of google.translate, my startActivity(intent) does not find it.

What would be the right intent.SetType or the right intent.WrapAsIntentChooser for an off-line translation app?

Any ideas?
john m.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Based on this answer: https://stackoverflow.com/questions...ctivity-not-working-anymore/20321335#20321335

B4X:
Sub Activity_Click
   Translate("ניסיון אחד שניים שלוש", "he", "en")
End Sub

Sub Translate(Text As String, SourceLanguage As String, TargetLanguage As String)
   Dim i As Intent
   i.Initialize(i.ACTION_VIEW, $"http://translate.google.com/m/translate?q=${Text}&sl=${SourceLanguage}&tl=${TargetLanguage}"$)
   Dim jo As JavaObject = i
   jo.RunMethod("setPackage", Array("com.google.android.apps.translate"))
   Try
     StartActivity(i)
   Catch
     Log(LastException)
   End Try
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

johnmie

Active Member
Licensed User
Longtime User
Thank you very much, Erel.
It works even offline, provided the user has installed the right language package.
BUT the google page stays open, even if I click on the 'copy' button. No way to return to my app.

Would it be possible to launch it in a webView or send it keystroke to disappear?
john m.
 
Upvote 0

johnmie

Active Member
Licensed User
Longtime User
I can start the off-line google translator all right, but to use the translated text in my app, the user has to click on the "copy" button and then several times on the back button on the device.

Is there a better way, e.g. getting the app to close itself once the "copy" button has been pressed?
john m.
 
Upvote 0
Top