Displaying a web page in your application
When you want to display HTML content on a web page, you have two choices: call the default browser or display them within your app. If you just want to call the default browser, use an Intent as follows:
Uri uri = Uri.parse("https://www.packtpub.com/"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent);
If you need to display the content within your own application, you can use the WebView
. This recipe will show how to display a web page in your application, as can be seen in this screenshot:
Getting ready
Create a new project in Android Studio and call it WebView
. Use the default Phone & Tablet option and select Empty Activity when prompted for Activity Type.
How to do it...
We're going to create the WebView
through code so we won't be modifying the layout. We'll start by opening the Android Manifest and following these steps:
Add the following permission:
<uses-permission android:name="android.permission.INTERNET"/>
Modify...