Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone give one exact example of webview implementation in android

Tags:

Hi I am developing android application using WebView implementation.

I followed the official android tutorial.

I am not getting errors when building my project in eclipse, but when running the application :

the application has stopped working unexpectedly

like image 375
Quick learner Avatar asked Dec 23 '11 09:12

Quick learner


2 Answers

Your Java file should be like this:

public class WebViewSampleActivity extends Activity {      WebView wb;     private class HelloWebViewClient extends WebViewClient {         @Override         public boolean shouldOverrideUrlLoading(WebView view, String url) {             return false;         }     }     /** Called when the activity is first created. */     @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);               wb=(WebView)findViewById(R.id.webView1);                 wb.getSettings().setJavaScriptEnabled(true);         wb.getSettings().setLoadWithOverviewMode(true);         wb.getSettings().setUseWideViewPort(true);         wb.getSettings().setBuiltInZoomControls(true);         wb.getSettings().setPluginState(WebSettings.PluginState.ON);         wb.getSettings().setPluginsEnabled(true);                    wb.setWebViewClient(new HelloWebViewClient());         wb.loadUrl("http://www.examplefoo.com");             } } 

Your xml file should be like this:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical"      android:layout_gravity="center">      <WebView         android:id="@+id/webView1"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:layout_gravity="center" />  </LinearLayout> 

Use the following in your manifest after <uses-sdk><uses-sdk/>:

 <uses-permission android:name="android.permission.INTERNET"/> 
like image 108
Ghost Avatar answered Oct 16 '22 11:10

Ghost


Android WebView loadurl example

Android WebView Example

WebView used to show webpages in our app. Let's make a WebView and load any website

provide permission in AndroidManifest.XML

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

activity_main.xml

 <?xml version="1.0" encoding="utf-8"?> <WebView xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/webview"     android:layout_width="match_parent"     android:layout_height="match_parent" /> 

MainActivity.Java

import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.webkit.WebView;  public class MainActivity extends AppCompatActivity { private WebView webview;  @Override protected void onCreate(Bundle savedInstanceState)  { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);  webview=(WebView)findViewById(R.id.webview); //loads androidride homepage to webview webview.loadUrl("https://www.androidride.com"); } } 
like image 26
Thomas Daniel Avatar answered Oct 16 '22 11:10

Thomas Daniel