In Kotlin how do I open a link in new Window

11,889

You can try this one, might be helpful, open new tab of web browser like

fun openNewTabWindow(urls: String, context : Context) {
    val uris = Uri.parse(urls)
    val intents = Intent(Intent.ACTION_VIEW, uris)
    val b = Bundle()
    b.putBoolean("new_window", true)
    intents.putExtras(b)
    context.startActivity(intents)
}
Share:
11,889
Admin
Author by

Admin

Updated on June 18, 2022

Comments

  • Admin
    Admin almost 2 years

    I am a tyro in Kotlin but I have a good Knowledge of Android and Core java. I am stuck on one condition while developing an android app via the Kotlin assistance.

    I want that when user clicks a link present on the pdf document; the link should be opened on a browser (and if browser is opened then the link should open on the new window not new tab of the same window ).

    I have achieved much of my objective but I didn't found out how to open a link in the new Window if the browser is open already?

    I have tried the code below(when the link on the pdf is clicked then it redirects to the below function call):

    fun web_page_open(urls: String) { // for more than one url
        val uris = Uri.parse(urls)
        val intents = Intent(Intent.ACTION_VIEW, uris)
        startActivity(intents)
    } 
    

    I have tried my level-best to explain my problem and also searched a lot(on github as well) but all my efforts went in vein.

    Any help is warmly welcomed.

    EDIT: Let's consider an instance if the user has already opened the default browser (say ABZfox) then when the link inside the pdf(or a doc) is clicked then the new Window of ABZfox opens instead of the same window in which the user was previously working. I'm sure the question makes some sense now!!!

    • Mohit Suthar
      Mohit Suthar over 6 years
      In which browser having new window functionality?
    • Stanislav Bondar
      Stanislav Bondar over 6 years
      You can't get new instance of browser and launch new window. If you need totally new window use your's activity with kind of pdf reader
    • Admin
      Admin over 6 years
      Sir(@Mohit Suthar) what does that mean?
    • Mohit Suthar
      Mohit Suthar over 6 years
      Means, I think default crome brouser not having a new window functionality, you can open new tab instead
    • Admin
      Admin over 6 years
      Sir(Stanislav Bondar) but I think that I used this functionality many times but not in kotlin!!! Sir I want that if the browser is opened already then this link should open in new Window and it is possible across many platforms.Isn't it?
    • Admin
      Admin over 6 years
      Sir(@Mohit Suthar) lets consider that the user has made Chrome his default browser then it can be done?
    • Mohit Suthar
      Mohit Suthar over 6 years
      You can open a new tab not new window
  • Admin
    Admin over 6 years
    Thanks a lot for your precious time Sir but I have worked that out already!!!Also I think I need to dig deeper myself and get it done.
  • muad-dweeb
    muad-dweeb over 3 years
    I don't understand this answer, because I don't understand where it goes in the code, or when and where to reference this function once it's defined.