Android Question How to launch Google.Translate offline version?

Discussion in 'Android Questions' started by John W. Miescher, Nov 27, 2017.

  1. John W. Miescher

    John W. Miescher Member Licensed 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.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Based on this answer: https://stackoverflow.com/questions...ctivity-not-working-anymore/20321335#20321335

    Code:
    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
     
  3. DonManfred

    DonManfred Expert Licensed User

    I may misunderstood the TO but i think the TO is searching for an OFFLINE solution.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Google Translare can work offline depending on its settings.
     
  5. John W. Miescher

    John W. Miescher Member Licensed 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.
     
  6. DonManfred

    DonManfred Expert Licensed User

    It is a APP you are launcing. You can not launch a 3rd party app in a Webview.

    You can press back-key in the app to return to your app.
     
    Rockefeller Goldman likes this.
  7. Erel

    Erel Administrator Staff Member Licensed User

    As DonManfred wrote there is no good way to control the other application.

    You can start an activity from the starter service after X seconds.
     
    Rockefeller Goldman likes this.
  8. John W. Miescher

    John W. Miescher Member Licensed 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.
     
    Rockefeller Goldman likes this.
  9. Erel

    Erel Administrator Staff Member Licensed User

    No.
     
    Rockefeller Goldman likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice