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.java
file. - Locate the line 33 containing the
ALLOWED_URL
constant. - Replace the value of the
ALLOWED_URL
constant with the desired URL for the allowed site.private static final String ALLOWED_URL = "www.example.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.java
file, locate the line 34 containing theFORCE_PORTRAIT
constant. - Replace the value of the
FORCE_PORTRAIT
constant totrue
to enforce portrait mode orfalse
to allow the system and user preferences to determine the screen orientation.private static final boolean FORCE_PORTRAIT = true; // Change this value to true or false
- 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.