Monday, February 22, 2016

Webview android studio Full

Hi guy

Follow me Now Create Webview !!! 



  •  in class MainActivity

import com.google.ads.mediation.AbstractAdViewAdapter;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity {

            private WebView myWebView;
    /**     * ATTENTION: This was auto-generated to implement the App Indexing API.     * See https://g.co/AppIndexing/AndroidStudio for more information.     */    private GoogleApiClient client;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



       /*String url1 = "http://mathematicalchill.blogspot.com" ;        WebView view = (WebView) this.findViewById(R.id.webView);        view.getSettings().setJavaScriptEnabled(true);        view.setWebViewClient(new WebViewClient());*/        WebView myWebView = (WebView) findViewById(R.id.webView);
        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        myWebView.loadUrl("http://mathematicalchill.blogspot.com");
        myWebView.setWebViewClient(new MyAppWebViewClient());



        // Load an ad into the AdMob banner view.        AdView adView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder()
                .setRequestAgent("android_studio:ad_template").build();
        adView.loadAd(adRequest);

        // Toasts the test ad message on the screen. Remove this after defining your own ad unit ID.
        // ATTENTION: This was auto-generated to implement the App Indexing API.        // See https://g.co/AppIndexing/AndroidStudio for more information.        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }

    @Override    public void onBackPressed()
    {
        if (myWebView.canGoBack()) {
            myWebView.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();

        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override    public void onStart() {
        super.onStart();

        // ATTENTION: This was auto-generated to implement the App Indexing API.        // See https://g.co/AppIndexing/AndroidStudio for more information.        client.connect();
        Action viewAction = Action.newAction(
                Action.TYPE_VIEW, // TODO: choose an action type.                "Main Page", // TODO: Define a title for the content shown.                // TODO: If you have web page content that matches this app activity's content,                // make sure this auto-generated web page URL is correct.                // Otherwise, set the URL to null.                Uri.parse("http://host/path"),
                // TODO: Make sure this auto-generated app deep link URI is correct.                Uri.parse("android-app://com.(Youpackage)/http/host/path")
        );
        AppIndex.AppIndexApi.start(client, viewAction);
    }

    @Override    public void onStop() {
        super.onStop();

        // ATTENTION: This was auto-generated to implement the App Indexing API.        // See https://g.co/AppIndexing/AndroidStudio for more information.        Action viewAction = Action.newAction(
                Action.TYPE_VIEW, // TODO: choose an action type.                "Main Page", // TODO: Define a title for the content shown.                // TODO: If you have web page content that matches this app activity's content,                // make sure this auto-generated web page URL is correct.                // Otherwise, set the URL to null.                Uri.parse("http://host/path"),
                // TODO: Make sure this auto-generated app deep link URI is correct.                Uri.parse("android-app://com.(Youpackage)/http/host/path")
        );
        AppIndex.AppIndexApi.end(client, viewAction);
        client.disconnect();
    }

    private class MyAppWebViewClient extends WebViewClient {
    }


}

  • inclass MyAppWebviewClient


import android.content.Intent;import android.net.Uri;import android.webkit.WebView;import android.webkit.WebViewClient;
/** * Created by maxx on 22/2/2559. */public class MyAppWebViewClient extends WebViewClient {


    @Override    public boolean shouldOverrideUrlLoading(WebView view, String url){

        if(Uri.parse(url).getHost().endsWith("http://mathematicalchill.blogspot.com")) {
            return false;
        }

        Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
        view.getContext().startActivity(intent);
        return true;
    }
}



Now check parameter is correct



No comments:

Post a Comment

Comments system

Disqus Shortname

Disqus Shortname

Comments system