In Kotlin how do I open a link in new Window
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)
}
Admin
Updated on June 18, 2022Comments
-
Admin almost 2 years
I am a tyro in
Kotlin
but I have a good Knowledge ofAndroid
andCore java
. I am stuck on one condition while developing an android app via theKotlin
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 over 6 yearsIn which browser having new window functionality?
-
Stanislav Bondar over 6 yearsYou 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 over 6 yearsSir(@Mohit Suthar) what does that mean?
-
Mohit Suthar over 6 yearsMeans, I think default crome brouser not having a new window functionality, you can open new tab instead
-
Admin over 6 yearsSir(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 over 6 yearsSir(@Mohit Suthar) lets consider that the user has made Chrome his default browser then it can be done?
-
Mohit Suthar over 6 yearsYou can open a new tab not new window
-
-
Admin over 6 yearsThanks 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 over 3 yearsI 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.