首页 文章

从意图打开浏览器后,如何验证URL是否已正确加载?

提问于
浏览
0

我打开设备浏览器到意图的特定URL,如下所示:

String url = "http://www.google.com";
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

我现在如何验证页面是否已在浏览器中成功加载?有没有办法返回浏览器应用程序的加载状态或内容?

2 回答

  • 0

    你可以试试这个

    try
    {
    
        String url = "http://www.google.com";
        Uri uri = Uri.parse(url);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
    
    }
    catch (MalformedURLException e) 
    {
                  e.printStackTrace();
    }
    

    希望有所帮助

  • 0

    您可以使用 onPageFinished()onReceivedError() 方法实现 WebViewClient

    myWebView.setWebViewClient(new WebViewClient() {
           public void onPageFinished(WebView view, String url) {
                Log.i("WebView", "Page succesfully loaded!");
            }
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
    Log.e("WebView", "An error ocurred: " + description + " loading the page:" + failingUrl + ", with code" + errorCode);       }
    
        });
    

    有关可能的错误代码的信息:http://developer.android.com/reference/android/webkit/WebViewClient.html#Summary

    更多信息:

    WebViewClient

相关问题