How convert any website into android app ?.

Android’s Web View permits you to integrate a webpage as an area of the app. Web View comes with all the options that of a desktop browser like managing history, cookies, HTML 5 support and heap a lot ofvictimization web view you'll be able to build very cool apps like group action HTML 5 games within the app.


In this article we tend to  planning to learn the essential usage of Web View ranging from displaying a netpage to putting together an easy in-app browser that has some web site and search web address.

A read that displays websites. This category is that the basis upon that you'll be able to roll your own applications programme or just show some on-line content among your Activity. It uses the WebKit rendering engine to show websites and includes ways to navigate forward and backward through a history, concentrate and out, perform text searches and a lot of.


Note that, so as for your Activity to access the net and cargo websites during a WebView, you need to add the net permissions to your automaton Manifest file:

<uses-permission android:name="android.permission.INTERNET" />

Basic usage:

By default, a WebView provides no browser-like widgets, doesn't alter JavaScript and web content errors area unit unheeded. If your goal is simply to show some markup language as a region of your UI, this can be most likely fine; the user will not have to be compelled to act with the net page on the far side reading it, and therefore the web content will not have to be compelled to act with the user. If you really desire a full-blown applications programme, then you most likely need to invoke the Browser application with a address Intent instead of show it with a WebView. For example:

Uri uri = Uri.parse("https://www.example.com");
 Intent intent = new Intent(Intent.ACTION_VIEW, uri);
 startActivity(intent);
 
1:Create a android project in MainActivity.xml put below code for web browser design

main_activity.xml :

 <?xml version="1.0" encoding="utf-8"?>  
 <RelativeLayout 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"  
 android:padding="10dp"  
 tools:context="com.example.aaru.mybrowser.MainActivity"> 
 <EditText  
 android:id="@+id/editSearch"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_alignParentStart="true"
 android:layout_alignParentTop="true"
 android:ems="10"
 android:hint="https://www.google.com"
 android:inputType="none" />
 <Button  
 android:id="@+id/buttonSearch"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentEnd="true"
 android:layout_alignParentRight="true"
 android:backgroundTint="@color/colorAccent"
 android:layout_alignParentTop="true"
 android:layout_toRightOf="@+id/editSearch"
 android:text="Search" />
 <Button  
 android:id="@+id/buttonGoogle"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:backgroundTint="#f75252"
 android:layout_marginTop="96dp"
 android:text="Google"
 android:layout_below="@+id/buttonSearch"
 android:layout_alignParentLeft="true"
 android:layout_alignParentStart="true"
 android:layout_alignParentRight="true"
 android:layout_alignParentEnd="true" /> 
 <Button  
 android:id="@+id/buttonFacebook"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginTop="58dp"
 android:text="Facebook"
 android:layout_below="@+id/buttonGoogle"
 android:layout_alignParentLeft="true"
 android:layout_alignParentStart="true"
 android:backgroundTint="#45c2c9"
 android:layout_alignParentRight="true"
 android:layout_alignParentEnd="true" /> 
 <Button  
 android:id="@+id/buttonGmail"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentEnd="true"
 android:layout_alignParentLeft="true"
 android:layout_alignParentRight="true"
 android:backgroundTint="#b34fda"
 android:layout_alignParentStart="true"
 android:layout_below="@+id/buttonFacebook"
 android:layout_marginTop="60dp"
 android:text="Gmail" /> 
 </RelativeLayout>  

Main Activity.java : In this class implantation the web browser design


 package com.example.aaru.mybrowser;
 import android.content.Intent;
 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.Button;
 import android.widget.EditText;
 public class MainActivity extends AppCompatActivity implements View.OnClickListener 
 Button buttonSearch,buttonGoogle,buttonFacebook,buttonGmail;  
   EditText editSearch; 
 @Override  
protected void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main); 
 editSearch=(EditText)findViewById(R.id.editSearch);
 buttonSearch= (Button) findViewById(R.id.buttonSearch);
 buttonGoogle= (Button) findViewById(R.id.buttonGoogle); 
 buttonFacebook= (Button) findViewById(R.id.buttonFacebook); 
 buttonGmail= (Button) findViewById(R.id.buttonGmail);  
     //all id get
 buttonSearch.setOnClickListener(this); 
 buttonGoogle.setOnClickListener(this); 
 buttonFacebook.setOnClickListener(this); 
 buttonGmail.setOnClickListener(this); 
 }  
   @Override
 public void onClick(View v) {
 Intent i=new Intent(MainActivity.this,WebViewActivity.class);
 if (v.equals(buttonSearch)){
 String url=editSearch.getText().toString();
 i.putExtra("k1",url);  
       startActivity(i); 
 }else if (v.equals(buttonGoogle))
 i.putExtra("k1","https://google.co.in"); 
 startActivity(i); 
 }else if (v.equals(buttonFacebook)){ 
 i.putExtra("k1","https://facebook.com"); 
 startActivity(i); 
 }else if (v.equals(buttonGmail)){
 i.putExtra("k1","https://mail.google.com"); 
 startActivity(i); 
 }  
   }  
 }  






2.Create empty activity name is webview activity put below code in web_view_activity.xml and WebViewActivity.java


web_view_activity.xml :



 <?xml version="1.0" encoding="utf-8"?>  
 <LinearLayout 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"  
 android:orientation="vertical"  
 tools:context="com.example.aaru.mybrowser.WebViewActivity">  
 <WebView  
 android:layout_width="match_parent"  
 android:layout_height="match_parent"  
 android:id="@+id/webView"  
 ></WebView>  
 </LinearLayout>  


WebViewActivity.java :


 package com.example.aaru.mybrowser;  
 import android.support.v7.app.AppCompatActivity;  
 import android.os.Bundle;  
 import android.webkit.WebView;  
 import android.webkit.WebViewClient;  
 import android.widget.Toast;  
 public class WebViewActivity extends AppCompatActivity {  
   WebView webView;  
   @Override 
 protected void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.activity_web_view);  
     webView=(WebView)findViewById(R.id.webView);  
     String url=getIntent().getStringExtra("k1");  
     if (url.contains("https://")){  
       webView.loadUrl(url);  
       webView.setWebViewClient(new WebViewClient());  
       webView.getSettings().setJavaScriptEnabled(true);  
       //let's run it  
       //Give a Internet Permission in manifests file  
     }else {  
       Toast.makeText(this, "Something Went wrong", Toast.LENGTH_SHORT).show();  
     }  
   }  
 }  

A WebView has many customization points wherever you'll be able to add your own behavior. These are:
 Creating and setting a WebChromeClient taxonomic category. 
 This category is named once one thing which may impact a browser UI happens, as an     example, progress updates and JavaScript alerts area unit sent here (see Debugging Tasks).
Creating and setting a WebViewClient taxonomic category. it'll be known as once things happen that impact the rendering of the content, eg, errors or kind submissions. you'll be able to conjointly intercept uniform resource locator loading here (via shouldOverrideUrlLoading()).
Modifying the WebSettings, like enabling  JavaScript with setJavaScriptEnabled().

Injecting Java objects into the WebView using the addJavascriptInterface(Object, String) technique. This technique permits you to inject Java objects into a page's JavaScript context, so they'll be accessed by JavaScript within the page.







>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Enjoy Coding<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Comments

  1. Wow! What a beautiful list of information. Too much. A good thing is how much I’ve learned from this. It’s that good!. Could you share your review on! convert wordpress site to progressive web app

    ReplyDelete

Post a Comment

Please Comment if Any Query !!