KOTLIN_BROADCAST Telegram 1725
🏝 Как в Kotlin Multiplatform открыть ссылку в системном браузере

// Kotlin Common Code
expect fun openInBrowser(
url: String,
completionHandler: (Boolean) -> Unit = {}
)

// Kotlin iOS Common
actual fun openInBrowser(
url: String,
completionHandler: (Boolean) -> Unit
) {
NSURL.URLWithString(url)?.let {
UIApplication.sharedApplication.openURL(
url = it,
options = emptyMap<Any?, Any>(),
completionHandler = completionHandler
)
}
}

actual fun openInBrowser(
url: String,
completionHandler: (Boolean) -> Unit
) {
val result = try {
context.startActivity(
Intent(Intent.ACTION_VIEW, Uri.parse(url))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
true
} catch (_: ActivityNotFoundException) {
false
}
completionHandler(result)
}

// Kotlin JVM Desktop Common
actual fun openInBrowser(
url: String,
completionHandler: (Boolean) -> Unit
) {
with(Desktop.getDesktop()) {
val result = if (isSupported(Desktop.Action.BROWSE)) {
try {
browse(URI.create(url))
true
} catch (e: IOException) {
false
} catch (e: SecurityException) {
false
}
} else false
completionHandler(result)
}
}


Источник тут

#kmp #kotlin
Please open Telegram to view this post
VIEW IN TELEGRAM



tgoop.com/kotlin_broadcast/1725
Create:
Last Update:

🏝 Как в Kotlin Multiplatform открыть ссылку в системном браузере

// Kotlin Common Code
expect fun openInBrowser(
url: String,
completionHandler: (Boolean) -> Unit = {}
)

// Kotlin iOS Common
actual fun openInBrowser(
url: String,
completionHandler: (Boolean) -> Unit
) {
NSURL.URLWithString(url)?.let {
UIApplication.sharedApplication.openURL(
url = it,
options = emptyMap<Any?, Any>(),
completionHandler = completionHandler
)
}
}

actual fun openInBrowser(
url: String,
completionHandler: (Boolean) -> Unit
) {
val result = try {
context.startActivity(
Intent(Intent.ACTION_VIEW, Uri.parse(url))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
true
} catch (_: ActivityNotFoundException) {
false
}
completionHandler(result)
}

// Kotlin JVM Desktop Common
actual fun openInBrowser(
url: String,
completionHandler: (Boolean) -> Unit
) {
with(Desktop.getDesktop()) {
val result = if (isSupported(Desktop.Action.BROWSE)) {
try {
browse(URI.create(url))
true
} catch (e: IOException) {
false
} catch (e: SecurityException) {
false
}
} else false
completionHandler(result)
}
}


Источник тут

#kmp #kotlin

BY Kotlin Multiplatform Broadcast


Share with your friend now:
tgoop.com/kotlin_broadcast/1725

View MORE
Open in Telegram


Telegram News

Date: |

"Doxxing content is forbidden on Telegram and our moderators routinely remove such content from around the world," said a spokesman for the messaging app, Remi Vaughn. Hui said the messages, which included urging the disruption of airport operations, were attempts to incite followers to make use of poisonous, corrosive or flammable substances to vandalize police vehicles, and also called on others to make weapons to harm police. Add up to 50 administrators SUCK Channel Telegram Ng was convicted in April for conspiracy to incite a riot, public nuisance, arson, criminal damage, manufacturing of explosives, administering poison and wounding with intent to do grievous bodily harm between October 2019 and June 2020.
from us


Telegram Kotlin Multiplatform Broadcast
FROM American