How to Create Mobile Application of a Website
Hello everyone , making Mobile apps of a website is growing day by day for handset users. Today I am going to share how to create a Mobile Apps of a website .The utility of this application is to easy access of website from our handsets . we need clear concept how to make the application. Let’s check out below.
Prerequisites:
- JDK 6.0 or above
- Android Studio
Steps to follow:
- Create a New Android Studio project name Myblog.
- Select minimum API level 16 so it will run 82.6%of Android device that are Active on google Play then click next.
- Select Blank Activity and your Activity name is MainActivity click next > click finish.
- Now Create a new class called Splashscreen.java .Inside Splashscreen.java write the following code.
public class SplashScreen extends Activity
{
private boolean mIsBackButtonPressed;
private static final int SPLASH_DURATION = 3000; // 3 seconds
private Handler myhandler;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
myhandler = new Handler();
// run a thread to start the home screen
myhandler.postDelayed(new Runnable()
{
@Override
public void run()
{
if (isWorkingInternetPersent()) {
finish();
Intent intent = new Intent(getBaseContext(), MainActivity.class);
startActivity(intent);
} else {
setContentView(R.layout.internet);
}
}
}, SPLASH_DURATION);
}
public boolean isWorkingInternetPersent() {
ConnectivityManager connectivityManager = (ConnectivityManager) getBaseContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager != null) {
NetworkInfo[] info = connectivityManager.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
return false;
}
//handle back button press
@Override
public void onBackPressed()
{
super.onBackPressed();
}
}
{
private boolean mIsBackButtonPressed;
private static final int SPLASH_DURATION = 3000; // 3 seconds
private Handler myhandler;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
myhandler = new Handler();
// run a thread to start the home screen
myhandler.postDelayed(new Runnable()
{
@Override
public void run()
{
if (isWorkingInternetPersent()) {
finish();
Intent intent = new Intent(getBaseContext(), MainActivity.class);
startActivity(intent);
} else {
setContentView(R.layout.internet);
}
}
}, SPLASH_DURATION);
}
public boolean isWorkingInternetPersent() {
ConnectivityManager connectivityManager = (ConnectivityManager) getBaseContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager != null) {
NetworkInfo[] info = connectivityManager.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
return false;
}
//handle back button press
@Override
public void onBackPressed()
{
super.onBackPressed();
}
}
5. Now Splashscreen.java will call MainActivity. Inside MainActivity.java write the following code.
public class MainActivity extends Activity {
WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv = (WebView)findViewById(R.id.webView);
WebSettings settings = wv.getSettings();
settings.setJavaScriptEnabled(true);
wv.loadUrl("http://www.uandblog.com/");
wv.setWebViewClient(new MobWebViewClient());
}
@Override
public void onBackPressed() {
if(wv.canGoBack()){
wv.goBack();
}else{
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private class MobWebViewClient extends WebViewClient {
}
}
WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv = (WebView)findViewById(R.id.webView);
WebSettings settings = wv.getSettings();
settings.setJavaScriptEnabled(true);
wv.loadUrl("http://www.uandblog.com/");
wv.setWebViewClient(new MobWebViewClient());
}
@Override
public void onBackPressed() {
if(wv.canGoBack()){
wv.goBack();
}else{
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private class MobWebViewClient extends WebViewClient {
}
}
6. Now you have to create Another class named MobWebViewClient.java . Inside this class write the following code.
public class MobWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(Uri.parse(url).getHost().endsWith("www.uandblog.com")){
return false;
}
Intent in = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
view.getContext().startActivity(in);
return true;
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(Uri.parse(url).getHost().endsWith("www.uandblog.com")){
return false;
}
Intent in = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
view.getContext().startActivity(in);
return true;
}
}
7.the required xml files are like below
splash.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="30sp"
android:text="Loading..."
android:id="@+id/textView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="@+id/webView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="@+id/webView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout>
Internet.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@mipmap/net_img"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="69dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="No Internet Connection"
android:textSize="30sp"
android:textColor="#000000"
android:id="@+id/textView2"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@mipmap/net_img"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="69dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="No Internet Connection"
android:textSize="30sp"
android:textColor="#000000"
android:id="@+id/textView2"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"/>
</RelativeLayout>

You may also like
Comments ( 2 )

John Piao:
thanks a lot
thanks a lot

Admin:
u are welcome
u are welcome

Amar Jyoti:
How to add no internet access error. Please Reply!!
How to add no internet access error. Please Reply!!
Subscribe Latest Information
Categories
Most Popular Posts
How to Withdraw Money from ATM Machine 7steps 1178785 Views
How to Create Chat Application in Android Studio 151637 Views
How to Create a Shopping Cart Application in Android 114499 Views
You May Like Also
How to create your first Android Game 15747 Views
How to Create Chat Application in Android Studio 151637 Views
How to Create a Shopping Cart Application in Android 114499 Views
How to Parse JSON data into Android Application 10278 Views