Did you know that you can create a basic web browsing android app for your website with just a few lines of code? Web browsing Android apps are great if you have a nice website and you want to make your brand’s application with just a minimal amount of code. At the same time, it is a great way to learn more about Android application development, and it doesn't require a background in application development. So, in this tutorial, I will teach you how to create a basic web browsing app of your own!
Before moving on with this tutorial you should know, how to set up the SDK and must have understanding of creating a basic Android app. Here's what we've covered so far on the subject. Just bear with this tutorial, and if you have difficulty understanding a concept, then you can go back to any one of these previous tutorials.
Alright, let’s move on with the tutorial!
Creating a web browsing App for Android
Step 1: Create a new Android Application project
Using Eclipse create a new Android application project (“WebBrowsingApp”). For this tutorial I have selected API 16 (Jelly Bean).
Step 2: Edit activity_main.xml
Open “activity_main.xml” and add the following code:
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
Step 3: Edit AndroidManifest.xml
Open “AndroidManifest.xml” and add the following code, after manifest tag:
<uses-permission android:name="android.permission.INTERNET" />
Basically we’ve provided internet access to our application.
Step 4: Edit MainActivity.java
Finally edit “MainActivity.java”. Copy the following libraries:
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebView;
import android.webkit.WebViewClient;
Now, overwrite the “public boolean onCreateOptionsMenu(Menu menu)” function with:
@SuppressLint("SetJavaScriptEnabled") @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
myWebView.loadUrl("http://www.mybloggertricks.com");
return true;
}
Your MainActivity.java class should look like this;
Step 5: Execute
Now, it’s time to run our newly created web browsing app. Right click Project, and select Run as->Android application. It should look something like this.
Pretty simple, right? You can add more functionality, and deliver your content in a much more optimized fashion to make your app much more mobile user-friendly.
If you don't want to get yourself into Serious Technical Trouble while editing your Blog Template then just sit back and relax and let us do the Job for you at a fairly reasonable cost. Submit your order details by Clicking Here »
Why not creating a chrome app or extention instead?
ReplyDeleteRegards!
Nice article Qasim! Keep it up!
ReplyDeleteWish I had found this blog before. The advices in this post are very helpful and I surely will read the other posts of this series too. Thank you for posting this.
ReplyDeletehey i have got some errors so please solve those
ReplyDelete1. activity_main cannot be resolved or is not a field
2. unexpected namespace prefix "xmlns" found for tag WebView
Hi,
ReplyDeleteCan I see adsense advertorial on webkit?
Thank you
Please provide the application link you used to make the browser
ReplyDeleteI have a problem. I used the above code and executed the apk successfully in my android phone (moto e 1st gen) but the browser is unable to loadUrl I specified in the MainActivity.java. What should i do to fix it? Please help.
ReplyDeleteI am using Android Studio 2.1.3