Introduction
Android is one of the most popular operating structures for mobiles. In this article, I will show you the way to create a Web Browser Android application for the usage of Android Studio.
Requirements
- Android Studio model 2.3.3
- Little bit XML and JAVA knowledge.
- Android Emulator (or) Android mobile
- Download link (Android Studio)
- Steps to be followed
Follow these steps to create a web Browser Android application for the usage of Android Studio. I have included the source code above.
Step 1
Open Android Studio and start a New Android Studio Project.
Step 2
You can pick out your application call and pick out wherein your venture is stored. If you want to use C++ for coding the venture, mark the "Include C++ support", and click the "Next" button.
Now, pick the model of Android and choose the goal Android devices. Read more info at Android Training
Step 3
Now, add the pastime and click the "Next" button.
Add pastime name and click on "Finish".
Step 4
Go to activity_main.Xml, This XML document consists of the designing code for the app.
The XML code is given under.
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context="abu.webview.MainActivity">
- <android.support.v4.widget.SwipeRefreshLayout
- android:id="@+id/swipe"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <WebView
- android:id="@+id/webView"
- android:layout_width="match_parent"
- android:layout_height="match_parent"/>
- </android.support.v4.widget.SwipeRefreshLayout>
- </android.support.constraint.ConstraintLayout>
Step 5
We need to make network requests. So, upload net permissions in the AndroidManifest.Xml record.
The AndroidManifest.Xml code is given below.
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="abu.webview">
- <uses-permission android:name="android.permission.INTERNET"/>
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:roundIcon="@mipmap/ic_launcher_round"
- android:supportsRtl="true"
- android:theme="@style/AppTheme">
- <activity android:name=".MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
Step 6
Go to the app, proper click “Directory route”, then click on on the route and add a brand new folder named “Assets” in the foremost folder. The beneath template shows the way to add an error file. I have attached an error record.
Step 7
Go to Main Activity.Java. This Java software is the back-quit language for Android.
The Java code is given underneath.
- package abu.webview;
- import android.support.v4.widget.SwipeRefreshLayout;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.webkit.WebView;
- import android.webkit.WebViewClient;
- public class MainActivity extends AppCompatActivity {
- WebView webView;
- SwipeRefreshLayout swipe;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- swipe = (SwipeRefreshLayout)findViewById(R.id.swipe);
- swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
- @Override
- public void onRefresh() {
- WebAction();
- }
- });
- WebAction();
- }
- public void WebAction(){
- webView = (WebView) findViewById(R.id.webView);
- webView.getSettings().setJavaScriptEnabled(true);
- webView.getSettings().setAppCacheEnabled(true);
- webView.loadUrl("https://www.google.com/");
- swipe.setRefreshing(true);
- webView.setWebViewClient(new WebViewClient(){
- public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
- webView.loadUrl("file:///android_assets/error.html");
- }
- public void onPageFinished(WebView view, String url) {
- // do your stuff here
- swipe.setRefreshing(false);
- }
- });
- }
- @Override
- public void onBackPressed(){
- if (webView.canGoBack()){
- webView.goBack();
- }else {
- finish();
- }
- }
- }
Step 8
Now, either visit the menu bar and click "Make challenge" or press ctrl+f9 to debug the error.
Step 9
Then, click on the "Run" button or press shift+f10 to run the undertaking. Select the "digital machine" alternative and click on OK.
Conclusion
We have efficaciously created a Web Browser Android application for the use of Android Studio.
If you want to learn more about Android, then The Complete Android App Development Course is a great course, to begin with
No comments:
Post a Comment