Building a Web View with Kotlin and Android
What Will I Learn?
- You will learn how to build a Web View using Android and Kotlin
- You will learn about some of the basic android life cycle components
- You will learn how to build an application that uses intents and contexts to switch around various activities
Requirements
- Android Studio 3.0 or Android Studio Canary
- A basic understanding of the Android ecosystem
- A fair understanding of Kotlin or the Java programming language
Difficulty
- Intermediate
Description
In this video tutorial, we build a basic Android Web View using Kotlin. This project is a very good introduction to the basics of building Android Applications in general and with Kotlin. We make two separate activities with two Constraint-Layout XML views. The first activity just serves as a splash screen which helps to hide the loading of the Web View in the background. The primary activity makes use of a Web View and an Image View. The Web View implements basic functionality; it allows JavaScript to run in the browser and uses the back button to allow the user to move backwards through the browser's history.
We also add some error handling that checks to see if the device is connected to the internet while it tries to load the steemit webpage. Our Image View uses a Steem logo to create an animation to help signify to the user that the Web View is still loading the content. We also add an Alert Dialog which pops up in the event of an error. This Alert Dialog lets the user quit the application, reload the URL, or go directly into the network settings to fix their connection problems.
The source code for this project can be found here
Video Tutorial
Related Content
- Desktop Applications in Kotlin
- Intro to Kotlin Series
- Intro to Kotlin (Basic Types, Type Inference, Casting and Strings)
- Intro to Kotlin (Basic Operations and Collections)
- Intro to Kotlin (Control Flow and Conditionals)
- Intro to Kotlin (Functions in Kotlin)
- Intro to Kotlin (Advanced Functions)
- Intro to Kotlin (Classes, Visibility Modifiers, Objects)
- Intro to Kotlin (Nullables, Data Classes, Enum Classes and Sealed Classes)
- Intro to Kotlin (Interfaces, Inheritance, Type Alias and Abstract Classes)
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
that was extremely fast. Thank you very much for reading and watching my content.
It was very interesting, personally I haven't used Android Studio for a few years (and I hated it back then), so I'm surprised about that. Will definitely follow along when I'm back in the Netherlands and have access to my PC (don't think my shitty laptop will appreciate me trying to run Android Studio).
Its actually more light weight then it used to be believe it or not, but I take your point. Cheers mate.
Very nice. utopian-io stemsteem programming science education post I think the post needs to be seen by everyone so I shared the post and liked the post and commented the vote and I followed you. .....
https://steemit.com/africa/@steemitraj/introduction ......@steemitraj
[deleted]
Lets see, there are various ways to approach these particular issues.
android:hardwareAccelerated="true"
in the application tag. Also using the WebChromeClient, you can addWebSettings.PluginState.ON
andWebSettings.PluginState.ON_DEMAND
. If you are trying to load YouTube videos from online sources then you can also try adding meta data into the requests so that the device knows that it will be a video. You can also try building your own Iframe and then re-embedding the video into it with something like this:Past API v17 there are considerable security increases against XSS, of course this doesn't mean you wont encounter some however. What I usually do, is force my
shouldOverrideUrlLoading
function to be limited to the domain of the website that I am visiting. With some of the 3rd party things like YouTube also included in this check. And if the incoming URL is not in the domain then I force android to launch an intent and typically that deals with most issues. This way I can validate the origin of all of the requests made in the application.shouldInterceptRequest
is another method you can override if you want a bit more control over the resources that are on whatever webpage you are accessing. Just make sure to sanitize all inputs that might be susceptible to XSS (MiTM for instance) attacks as you would with any web app etc. I know there are some decent 3rd party librarys that can handle these things as well: OWASP for instance is a good one. jsoup can also help in some specific situations.WebViews are slow as are hybrid apps. Its one of the more unfortunate things (i would prefer to write views in HTML then XML). You can try to set a higher render priority for your webviews via
webview.getSettings().setRenderPriority(RenderPriority.HIGH);
and you can enable and disable hardware acceleration for various things. You can even downgrade the HTML you are viewing using modifiers likebody.lowquality * { filter: none !important; }
.If I had to build a semi-hybrid app like that I would probably use something that isn't a native android app like Dart's Flutter framework for the front-end. (I know that's probably more trouble then its worth at this point for you though). And then I would wire everything else that I could get via API into the native side of the app and use my own custom build UI elements. Anyways, I hope some of this helps you out.
Good
Hey @tensor I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Congratulations! This post has been upvoted from the communal account, @minnowsupport, by Tensor from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.
If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.
You got a 5.87% upvote from @upmewhale courtesy of @tensor!