λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
πŸ‘¨πŸΌ‍πŸ’»κ°œλ°œ/μ•ˆλ“œλ‘œμ΄λ“œ μŠ€νŠœλ””μ˜€

μ•ˆλ“œλ‘œμ΄λ“œ μŠ€νŠœλ””μ˜€ - μ›Ήλ·°(WebView) μžλ°”μŠ€ν¬λ¦½νŠΈ μ‘°μž‘

by Janger 2023. 8. 23.
728x90
λ°˜μ‘ν˜•
private Boolean isLoadingFinished = false;

...

WebView webView = findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient(){

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
        Toast.makeText(getApplicationContext(), "νŽ˜μ΄μ§€ λ‘œλ“œ 쀑...", Toast.LENGTH_LONG).show();
        isLoadingFinished = false;
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        if (webView.getProgress() == 100) {
            Toast.makeText(getApplicationContext(), "νŽ˜μ΄μ§€ λ‘œλ“œ μ™„λ£Œ.", Toast.LENGTH_LONG).show();
            isLoadingFinished = true;
        }
    }
});
webView.getSettings().setJavaScriptEnabled(true);

webView.loadUrl("http://172.30.1.254/mobile/login/login");

new Thread(new Runnable() {
    @Override
    public void run() {

        runOnUiThread(new Runnable() {
            @Override
            public void run() {

                while(true){
                    if(isLoadingFinished)
                        break;

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

                String script =
                        "$('#loginid').val('1234');" +
                        "$('#loginid').change();" +
                        "$('#loginpass').val('1234');" +
                        "$('#loginpass').change();";

                webView.loadUrl("javascript:function run(){ " + script + " }run();");
            }
        });

    }
}).start();

 

μ›Ήλ·°(WebView)λ‘œλΆ€ν„° 데이터 κ°€μ Έμ˜€κΈ°
// ν˜„μž¬ URL κ°€μ Έμ˜€κΈ°
String webUrl = webView.getUrl();


// element λ‚΄μš© κ°€μ Έμ˜€κΈ°
String js = "(function() { " +
        "return document.getElementById('my_element').innerHTML;" +
        "})()";

webView.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        view.evaluateJavascript(js, new ValueCallback<String>() {
            @Override
            public void onReceiveValue(String value) {
                // 'value' contains the result of the JavaScript code
                Log.d("WebView", "Data: " + value);
            }
        });
    }
});

 

 

좜처: 

https://stackoverflow.com/questions/23827460/how-to-get-the-current-page-url-from-the-web-view-in-android

 

how to get the current page url from the web view in android

Using webview.loadUrl(url) method I open an url. If I click any Button on the view it directs to another page. Now I want to get the url of the directed page. how can I get it? I also want the con...

stackoverflow.com

 

https://stackoverflow.com/questions/3149216/how-to-listen-for-a-webview-finishing-loading-a-url

 

How to listen for a WebView finishing loading a URL?

I have a WebView that is loading a page from the Internet. I want to show a ProgressBar until the loading is complete. How do I listen for the completion of page loading of a WebView?

stackoverflow.com

 

728x90
λ°˜μ‘ν˜•