Android - Simple Web Viewer

Submitted by: 
Operating System: 
Visitors have accessed this post 2699 times.

In this tutorial we will try to create a Simple Web Viewer using Android. This simple app can search through any sites as a browser. It used in several gadget like smartphone, tablet, and even television. Android is open source to developers who has an interest in developing mobile apps. It also provide an adaptive framework that allow the developer to develop an apps in a simpler way. So let's now do the coding...

Getting Started:

First you will have to download & install the Android Development IDE (Android Studio or Eclipse). Android Studio is an open source development feel free to develop your things.

Here's the link for the Android Studio https://developer.android.com/studio/index.html

Layout Design

We will now create the design for the application, first locate the layout file called activity_main.xml, this is the default name when create a new activity. Then write these codes inside your layout file.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="<a href="http://schemas.android.com/apk/res/android"
  3. " rel="nofollow">http://schemas.android.com/apk/res/android"
  4. </a> xmlns:app="<a href="http://schemas.android.com/apk/res-auto"
  5. " rel="nofollow">http://schemas.android.com/apk/res-auto"
  6. </a> xmlns:tools="<a href="http://schemas.android.com/tools"
  7. " rel="nofollow">http://schemas.android.com/tools"
  8. </a> android:layout_width="match_parent"
  9. android:layout_height="match_parent"
  10. tools:context="com.razormist.simplewebviewer.MainActivity">
  11.  
  12. android:id="@+id/btn_search"
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:text="Search"
  16. android:layout_toRightOf="@+id/et_url"
  17. android:layout_alignParentRight="true"/>
  18.  
  19. <EditText
  20. android:id="@+id/et_url"
  21. android:layout_width="wrap_content"
  22. android:layout_height="wrap_content"
  23. android:inputType="text"
  24. android:lines="1"
  25. android:ems="14"
  26. android:maxLines="1"
  27. android:layout_alignParentTop="true"
  28. android:hint="<a href="https://www."/>
  29.  
  30. " rel="nofollow">https://www."/>
  31.  
  32. </a> <WebView
  33. android:id="@+id/wv_browser"
  34. android:layout_width="match_parent"
  35. android:layout_height="match_parent"
  36. android:layout_centerHorizontal="true"
  37. android:layout_below="@+id/et_url" />
  38. </RelativeLayout>

Android Manifest File

The Android Manifest file provides essential information about your app to the Android system in which the system must required before running the code. It describe the overall information about the application. It contains some libraries that needed to access the several method within the app.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="<a href="http://schemas.android.com/apk/res/android"
  3. " rel="nofollow">http://schemas.android.com/apk/res/android"
  4. </a> package="com.razormist.simplewebviewer">
  5. <uses-permission android:name="android.permission.INTERNET"/>
  6. <application
  7. android:allowBackup="true"
  8. android:icon="@mipmap/ic_launcher"
  9. android:label="@string/app_name"
  10. android:roundIcon="@mipmap/ic_launcher_round"
  11. android:supportsRtl="true"
  12. android:theme="@style/AppTheme">
  13. <activity android:name=".MainActivity"
  14. android:configChanges="orientation"
  15. android:screenOrientation="portrait">
  16. <intent-filter>
  17. <action android:name="android.intent.action.MAIN" />
  18.  
  19. <category android:name="android.intent.category.LAUNCHER" />
  20. </intent-filter>
  21. </activity>
  22. </application>
  23.  
  24. </manifest>

The Main Function

This code contains the main function of the application. This code will try to render the website into the WebView when you clicked the button. To start with first locate your MainActivity java file and open it, then write these some important variables inside the MainActivity class.

  1. private Button btn_search;
  2. private EditText et_url;
  3. private WebView wv_browser;

Then write these several method inside the activity class to make the apps work properly.

  1. public void SearchSite(){
  2. btn_search = (Button)findViewById(R.id.btn_search);
  3. et_url = (EditText)findViewById(R.id.et_url);
  4. wv_browser = (WebView)findViewById(R.id.wv_browser);
  5.  
  6. btn_search.setOnClickListener(new View.OnClickListener() {
  7. @Override
  8. public void onClick(View v) {
  9. String url = "<a href="https://www."" rel="nofollow">https://www."</a> + et_url.getText().toString();
  10. wv_browser.getSettings().setLoadsImagesAutomatically(true);
  11. wv_browser.getSettings().setJavaScriptEnabled(true);
  12. wv_browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
  13. wv_browser.setWebViewClient(new WebViewClient());
  14. wv_browser.loadUrl(url);
  15. }
  16. });
  17. }

Finally, initialize all the methods inside the onCreate method to run the application.

  1. SearchSite();

Try to run the app and see if it worked.
Note: Make sure you have an internet connection to test if it browse to the internet.

There you have it we create a Simple Web Viewer using Android. I hope that this tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.