Webview卡在加载网站或Cloudfare检查中

时间:2019-04-01 06:15:48

标签: java android webview

您好,我正在尝试制作一个简单的Webview应用程序,以便为网站提供专用的“应用程序”。启用了Javascript,并且大多数网站(除了带有animeflv.net或floatplane.com的预Web检查的网站之外)均正常加载。在Android 8.0.0上运行代码

这是我的代码:

MainActivity.java

package com.example.floatplane;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
import android.net.http.*;
import android.webkit.WebViewClient;


public class MainActivity extends AppCompatActivity {

    private WebView myWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);



        String url = "https://floatplane.com/";
        myWebView = (WebView) this.findViewById(R.id.fpWebView);

        myWebView.getSettings().setJavaScriptEnabled(true);
        myWebView.setWebViewClient(new WebViewClient());
        myWebView.loadUrl(url);
    }

    @Override
    public void onBackPressed(){
        if(myWebView.canGoBack()){
            myWebView.goBack();
        }
        else
        {
            super.onBackPressed();
        }

    }


}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.floatplane">

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


    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">


        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>



</manifest>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <WebView
        android:id="@+id/fpWebView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>

任何有关如何强制加载页面或跳过任何检查的想法都将受到赞赏。

1 个答案:

答案 0 :(得分:1)

String userAgent = System.getProperty( "http.agent" );
Log.e("User agent",userAgent);
myWebView.setWebViewClient(new WebViewClient());
myWebView.getSettings().setUserAgentString(userAgent);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setAppCacheEnabled(true);
myWebView.getSettings().setDomStorageEnabled(true);
myWebView.loadUrl(url);

能否请您尝试此解决方案。在我的模拟器中使用android28。