The Android Restricted WebView is an Android application template that allows you to display a specific website using a WebView while restricting access to other sites. If the application attempts to load a URL other than the allowed site, an error message "This URL is not allowed" will be displayed.
To configure the application and set the allowed website, follow these steps:
- Open the project in Android Studio.
- Navigate to the
MainActivity.kt
file. - Locate the line 30 containing the
ALLOWED_DOMAINS
constant. - Replace the value of the
ALLOWED_DOMAINS
constant with the desired Domains for the allowed site.private val ALLOWED_DOMAINS = listOf("hadass.site", "ko-fi.com")
- Save the changes.
Make sure to provide a valid URL for the website you want to allow in the application.
The Android Restricted WebView also allows for the forcing of screen orientation to portrait mode. This is controlled by the FORCE_PORTRAIT
constant on line 31 in the MainActivity
class.
To configure this, follow these steps:
- In the
MainActivity.kt
file, locate the line 32 containing theFORCE_PORTRAIT
constant. - Replace the value of the
ORIENTATION_MODE
constant toOrientationMode.PORTRAIT
to enforce portrait mode orOrientationMode.AUTO
to allow the system and user preferences to determine the screen orientation.private val ORIENTATION_MODE = OrientationMode.AUTO //Chose between AUTO, PORTRAIT or LANDSCAPE
- Save the changes.
After modifying this value, you need to recompile and redeploy the application for the change to take effect.
To change the package name of the application, follow these steps:
- Open the project in Android Studio.
- Locate the
build.gradle
file (Module: app). - In the
build.gradle
file, find the line 9 containing theapplicationId
. - Replace the value of the
applicationId
with the desired package name.defaultConfig { // ... applicationId "com.example.newpackagename" // ... }
- Sync the project with Gradle to apply the changes.
Ensure that the new package name follows the proper naming conventions.
After configuring the allowed URL, setting the portrait mode preference, and optionally changing the package name, you can run the application on an Android emulator or device. The application will display the web page of the allowed site within the WebView.
If an attempt is made to load a URL other than the allowed site, the application will display an error message "This URL is not allowed" instead of the content.
This application is distributed under the GNU General Public License version 3 (GNU GPL-3.0). See the LICENSE file for more details.
Please note that I am not a lawyer and the information provided here should not be considered legal advice. It is important to consult with a qualified legal professional to ensure compliance with all relevant licensing requirements and obligations.