-1

Activity.java code:

package net.pocketcraftgaming.pocketcraftgaming;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.view.Menu;
import android.view.MenuItem;

public class WebMainActivity extends AppCompatActivity {

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

    String url ="http://www.pocketcraftgaming.net/";
    WebView view =(WebView) this.findViewById(R.id.webView);
    view.getSettings().setJavaScriptEnabled(true);
    view.loadUrl(url);
}
}

Tell me if I need to show my AndroidManifest.xml or activity.xml please reply soon!

Deividi Cavarzan
  • 10,034
  • 13
  • 66
  • 80

4 Answers4

2

In case you are not bound to only webview, you can have a look into this. Chrome Custom Tab

Here you can find more about Custom Tab.

Dhrumil Patel
  • 544
  • 6
  • 16
1

You have to set up WebViewClient . Add this:

this.mWebView.setWebViewClient(new WebViewClient(){

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url){
      view.loadUrl(url);
      return true;
    }
});
Jas
  • 3,207
  • 2
  • 15
  • 45
1

Try this way. put this in oncreate method.

String URL ="http://www.pocketcraftgaming.net/";
    if (URL.startsWith("http://")) {
    } else {
        URL = "http://" + getIntent().getStringExtra("WebUrl").trim();
    }
    // this is method.
    LoadURLinWebView(URL);

this is Load URL method.

private void LoadURLinWebView(String uRL2) {
    // TODO Auto-generated method stub
    WebView Wv_onlywebview =(WebView) this.findViewById(R.id.Wv_onlywebview);
    Wv_onlywebview.getSettings().setJavaScriptEnabled(true);
    Wv_onlywebview.setWebChromeClient(new WebChromeClient());
    Wv_onlywebview.setWebViewClient(new WebViewClient() {
        ProgressDialog progressDialog;

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        // Show loader on url load
        public void onLoadResource(WebView view, String url) {
            if (progressDialog == null) {
                progressDialog = new ProgressDialog(
                        Webview_Only_Activity.this);
                progressDialog.show();
            } else {
                progressDialog.dismiss();
            }
        }

        public void onPageFinished(WebView view, String url) {
            if (progressDialog.isShowing()) {
                progressDialog.dismiss();
                progressDialog = null;
            }
        }
    });
    Wv_onlywebview.loadUrl(uRL2);
}
Hardik Parmar
  • 712
  • 2
  • 13
  • 28
0

try this

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
Narendra Motwani
  • 1,085
  • 10
  • 20