January 2018
Intermediate to advanced
434 pages
14h 1m
English
The browse function provided by Anko is just a syntactic sugar, beneath which we have the same old code that we used previously:
fun Context.browse(url: String, newTask: Boolean = false): Boolean { try { val intent = Intent(Intent.ACTION_VIEW) intent.data = Uri.parse(url) if (newTask) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) } startActivity(intent) return true } catch (e: ActivityNotFoundException) { e.printStackTrace() return false }}
Calling this method returns true or false, based on whether the action was successful or not.
Read now
Unlock full access