Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript URL未在webview中加载,但已在android浏览器中加载?_Javascript_Android_Url_Webview - Fatal编程技术网

Javascript URL未在webview中加载,但已在android浏览器中加载?

Javascript URL未在webview中加载,但已在android浏览器中加载?,javascript,android,url,webview,Javascript,Android,Url,Webview,某些类型的URL未加载到Webview中的“我的应用”中,但可以加载到设备浏览器中。下面是示例Url,它在我的代码中不起作用- “” 创建WebViewClient并加载urllike public class myWebClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) {

某些类型的URL未加载到Webview中的“我的应用”中,但可以加载到设备浏览器中。下面是示例Url,它在我的代码中不起作用- “”


创建
WebViewClient
并加载
url
like

 public class myWebClient extends WebViewClient {
    @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                view.loadUrl(url);
                return true;
            }
}
setWebViewClient
类似:

    webView.setWebViewClient(new myWebClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl("http://apps.takeyourapp.com/testApp/staging/index.html");
还可以将
INTERNET
权限添加到
manifest.xml

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

试试这个解决方案

public class Main extends Activity {

    private WebView mWebview ;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        mWebview  = new WebView(this);

        mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript

        final Activity activity = this;

        mWebview.setWebViewClient(new WebViewClient() {
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
            }
        });

        mWebview .loadUrl("http://apps.takeyourapp.com/testApp/staging/index.html");
        setContentView(mWebview );

    }

}

不要从shouldOverrideUrlLoading调用view.loadUrl。只是返回错误;否则,像这样的页面会破坏你的应用程序:
public class Main extends Activity {

    private WebView mWebview ;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        mWebview  = new WebView(this);

        mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript

        final Activity activity = this;

        mWebview.setWebViewClient(new WebViewClient() {
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
            }
        });

        mWebview .loadUrl("http://apps.takeyourapp.com/testApp/staging/index.html");
        setContentView(mWebview );

    }

}