Java Code Examples for android.webkit.WebView#loadUrl()

The following examples show how to use android.webkit.WebView#loadUrl() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebActivity.java    From iot-starter-for-android with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.webview);

    if (savedInstanceState != null) {
        ((WebView)findViewById(R.id.webPage)).restoreState(savedInstanceState);
    }

    wv = (WebView) findViewById(R.id.webPage);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setDomStorageEnabled(true);
    wv.setWebChromeClient(new myWebChromeClient());

    IoTStarterApplication app = (IoTStarterApplication) getApplication();
    String url = Constants.QUICKSTART_URL + app.getDeviceId() + "/sensor/";
    Log.d(TAG, "Launching chromium with URL: " + url);
    if (savedInstanceState == null) {
        wv.loadUrl(url);
    }
}
 
Example 2
Source File: WebDialog.java    From Klyph with MIT License 6 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void setUpWebView(int margin) {
    LinearLayout webViewContainer = new LinearLayout(getContext());
    webView = new WebView(getContext());
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setWebViewClient(new DialogWebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(url);
    webView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    webView.setVisibility(View.INVISIBLE);
    webView.getSettings().setSavePassword(false);

    webViewContainer.setPadding(margin, margin, margin, margin);
    webViewContainer.addView(webView);
    webViewContainer.setBackgroundColor(BACKGROUND_GRAY);
    contentFrameLayout.addView(webViewContainer);
}
 
Example 3
Source File: Web3ViewClient.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
private boolean shouldOverrideUrlLoading(WebView webView, String url, boolean isMainFrame, boolean isRedirect) {
    boolean result = false;
    synchronized (lock) {
        isInjected = false;
    }
    String urlToOpen = urlHandlerManager.handle(url);
    //manually handle trusted intents
    if (handleTrustedApps(url))
    {
        return true;
    }

    if (!url.startsWith("http"))
    {
        result = true;
    }
    if (isMainFrame && isRedirect) {
        urlToOpen = url;
        result = true;
    }

    if (result && !TextUtils.isEmpty(urlToOpen)) {
        webView.loadUrl(urlToOpen);
    }
    return result;
}
 
Example 4
Source File: CameraListActivity.java    From Viewer with Apache License 2.0 6 votes vote down vote up
private void showDisclaimerDlg(){
	if(null != mDisclaimerDialog){
		mDisclaimerDialog.show();
	}else{
		WebView webView = new WebView(CameraListActivity.this);
		webView.loadUrl(mShowChinese ? DISCLAIMER_URL_CN : DISCLAIMER_URL_EN);
		mDisclaimerDialog = new AlertDialog.Builder(this)
		.setView(webView)
		.setTitle(R.string.disclaimer)
		.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
			}
		})
		.create();
		mDisclaimerDialog.show();
	}
}
 
Example 5
Source File: DataLegendActivity.java    From proofmode with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_data_legend);

    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    TextView title = toolbar.findViewById(R.id.toolbar_title);
    title.setText(getTitle());

    WebView webView = findViewById(R.id.webView);

    WebSettings webSetting = webView.getSettings();
    webSetting.setBuiltInZoomControls(false);
    webSetting.setJavaScriptEnabled(false);

    webView.setWebViewClient(new WebViewClient());
    webView.loadUrl("file:///android_asset/datalegend/datalegend.html");
}
 
Example 6
Source File: MarkDownNoteDetailActivity.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPageFinished(WebView view, String url) {
    final String hm=currentNoteInfo.content .replace("\\","\\\\").replace("\n","\\n").replace("\t","\\t");
    view.loadUrl("javascript:parseMarkdown('"+hm+"')");
    view.loadUrl("javascript:window.HtmlViewer.getHtml" +
            "(''+document.getElementById('content').innerHTML+'');");
    showTextNum(htmlString);
}
 
Example 7
Source File: ByWebViewClient.java    From ByWebView with Apache License 2.0 5 votes vote down vote up
@Override
    public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
        super.onReceivedHttpError(view, request, errorResponse);
//        WebTools.handleReceivedHttpError(view, errorResponse);
        // 这个方法在 android 6.0才出现
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            int statusCode = errorResponse.getStatusCode();
            if (404 == statusCode || 500 == statusCode) {
                String mErrorUrl = "file:///android_asset/404_error.html";
                view.loadUrl(mErrorUrl);
            }
        }
    }
 
Example 8
Source File: AboutFragment.java    From physical-web with Apache License 2.0 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void initializeWebView() {
  WebView webView = (WebView) getActivity().findViewById(R.id.about_webview);
  webView.getSettings().setJavaScriptEnabled(true);
  webView.setWebViewClient(new WebViewClient());
  webView.loadUrl(getString(R.string.url_getting_started));
}
 
Example 9
Source File: LicenseActivity.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mWebView = new WebView(this);
    mWebView.loadUrl("file:///android_asset/NOTICE.html");
    setContentView(mWebView);

    setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
}
 
Example 10
Source File: RMBTTermsFragment.java    From open-rmbt with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState)
{
    
    activity = getActivity();
    
    webview = new WebView(activity);
    
    /* JavaScript must be enabled if you want it to work, obviously */
    // webview.getSettings().setJavaScriptEnabled(true);
    
    webview.getSettings().setSupportZoom(true);
    webview.getSettings().setBuiltInZoomControls(true);
    
    webview.setWebViewClient(new WebViewClient()
    {
        @Override
        public void onReceivedError(final WebView view, final int errorCode, final String description,
                final String failingUrl)
        {
            super.onReceivedError(view, errorCode, description, failingUrl);
            webview.loadUrl("file:///android_res/raw/error.html");
        }
    });
    
    webview.loadUrl(this.getString(R.string.url_terms));
    
    return webview;
}
 
Example 11
Source File: VectorUtils.java    From zom-android-matrix with Apache License 2.0 5 votes vote down vote up
/**
 * Open a web view above the current activity.
 *
 * @param context the application context
 * @param url     the url to open
 */
private static void displayInWebView(final Context context, String url) {
    WebView wv = new WebView(context);
    wv.loadUrl(url);
    new AlertDialog.Builder(context)
            .setView(wv)
            .setPositiveButton(android.R.string.ok, null)
            .show();
}
 
Example 12
Source File: Applayout3Activity.java    From MaterialDesignDemo with MIT License 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_applayout3);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.loadUrl("https://github.com/GitLqr");
}
 
Example 13
Source File: LicensesActivity.java    From WanAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_licenses);
    setTitle(R.string.about_licenses);
    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("navigation_bar_tint", true)) {
        getWindow().setNavigationBarColor(ContextCompat.getColor(this,R.color.colorPrimaryDark));
    }
    setSupportActionBar((Toolbar) findViewById(R.id.toolBar));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    WebView webView = findViewById(R.id.web_view);
    webView.loadUrl("file:///android_asset/licenses.html");
}
 
Example 14
Source File: MarkDownNoteDetailActivity.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
public void parseMarkdown(String markdown,WebView webView){
    if(webView==null ){
        return;
    }
    final String hm=markdown.replace("\\","\\\\").replace("\n","\\n").replace("\t","\\t");
    webView.loadUrl("javascript:parseMarkdown('"+hm+"')");
    webView.loadUrl("javascript:window.HtmlViewer.getHtml" +
            "('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");
    showTextNum(htmlString);
}
 
Example 15
Source File: WebViewActivity.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    WebView webView = new WebView(this);
    setContentView(webView);

    String url = getIntent().getStringExtra(URL);
    String fileName = getIntent().getStringExtra(FILENAME);
    if (fileName != null) {
        url = "file:///android_asset/" + fileName + ".htm";

    }
    webView.loadUrl(url);
}
 
Example 16
Source File: WebTools.java    From ByWebView with Apache License 2.0 5 votes vote down vote up
/**
 * 2)重写WebChromeClient的onReceivedError()方法处理(该方法已过时)
 */
public static void handleReceivedError(WebView webView) {
    //6.0以下执行
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return;
    }
    String mErrorUrl = "file:///android_asset/404_error.html";
    webView.loadUrl(mErrorUrl);
}
 
Example 17
Source File: TutorialStep1.java    From watchpresenter with Apache License 2.0 5 votes vote down vote up
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.tutorial_layout, container, false);
    WebView wv = (WebView) v.findViewById(R.id.mainWebView);
    wv.loadUrl("file:///android_asset/tutorial/tutorial1.html");

    return v;
}
 
Example 18
Source File: LxwBlogActivity.java    From stynico with MIT License 4 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
    view.loadUrl(url);
    return true;
}
 
Example 19
Source File: CustomWebViewClient.java    From JsWebView with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceivedError(WebView view, int errorCode,
                            String description, String failingUrl) {
    view.loadUrl(onPageError(failingUrl));
}
 
Example 20
Source File: GSIDWebViewActivity.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    showProgress();
    view.loadUrl(url);
    return super.shouldOverrideUrlLoading(view, url);
}