在Android webView内部使用POST的外部站点按钮不起作用

在Android webView内部使用POST的外部站点按钮不起作用,android,post,webview,android-webview,Android,Post,Webview,Android Webview,我在webView中从外部网站获取按钮时遇到问题。该按钮似乎使用PHP Post。我注意到的一点是,URL使用参数,当按下按钮时,这些参数会发生更改。我在android浏览器中测试了外部站点,没有问题,但是当我使用webView时,我遇到了问题 抱歉,如果这篇文章的格式有误,这是我第一次在这里发帖。我在互联网上广泛搜索了这个问题,但没有找到解决方案 下面是Java代码 package com.example.jbzapp; import android.app.Activity; import

我在webView中从外部网站获取按钮时遇到问题。该按钮似乎使用PHP Post。我注意到的一点是,URL使用参数,当按下按钮时,这些参数会发生更改。我在android浏览器中测试了外部站点,没有问题,但是当我使用webView时,我遇到了问题

抱歉,如果这篇文章的格式有误,这是我第一次在这里发帖。我在互联网上广泛搜索了这个问题,但没有找到解决方案

下面是Java代码

package com.example.jbzapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

public class ScavHuntActivity extends Activity implements OnClickListener {

    Button events, scavHunt, gInfo, donations, home, animals, map, social;
    WebView webQuiz;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initLayout();
    }


    private void initLayout(){

        setContentView(R.layout.activity_scav_hunt);

        //load quiz from web
        webQuiz = (WebView)findViewById(R.id.webViewQuiz);

        //Alternative site, not going to use but it works fine.
        //webQuiz.loadUrl("http://www.qfeast.com/scored/quiz/10285/Quiz-Test");

        webQuiz.loadUrl("http://www.proprofs.com/quiz-school/story.php?title=quiz-test_103");       
        WebSettings webSettings = webQuiz.getSettings();
        //This did nothing
        //webSettings.setSupportMultipleWindows(true);
        webSettings.setJavaScriptEnabled(true);
        //webQuiz.reload();

        this.webQuiz.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url){

                view.loadUrl(url);
                view.loadUrl("javascript:window.location.reload( true )" );
                return true;
            }
        });



        events = (Button) findViewById(R.id.eventsButton); //Creating the button referencing it to the xml button created by ID.
        events.setOnClickListener(this); //Creates the on click listener that listens for the button click.

        scavHunt = (Button) findViewById(R.id.scavangerButton);
        scavHunt.setOnClickListener(this);

        gInfo = (Button) findViewById(R.id.generalButton);
        gInfo.setOnClickListener(this);

        donations = (Button) findViewById(R.id.donationsButton);
        donations.setOnClickListener(this);

        home = (Button) findViewById(R.id.homeButton);
        home.setOnClickListener(this);

        animals = (Button) findViewById(R.id.animalsButton);
        animals.setOnClickListener(this);

        map = (Button) findViewById(R.id.mapButton);
        map.setOnClickListener(this);

        social = (Button) findViewById(R.id.socialButton);
        social.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        final Intent eventsIntent = new Intent(this, EventsActivity.class); //Creating an intent that connects the HomeActivity.class with the EventsActivity.class
        final Intent scavHuntIntent = new Intent(this, ScavHuntActivity.class);
        final Intent gInfoIntent = new Intent(this, GInfoActivity.class);
        final Intent donationsIntent = new Intent(this, DonationsActivity.class);

        final Intent homeIntent = new Intent(this, HomeActivity.class);
        final Intent animalsIntent = new Intent(this, AnimalsActivity.class);
        final Intent mapIntent = new Intent(this, MapActivity.class);
        final Intent socialIntent = new Intent(this, SocialActivity.class);


        switch(v.getId()){
        case R.id.eventsButton:
            startActivity(eventsIntent); //on button click start activity with the intent to change view to EventsActivity.class
            break;
        case R.id.scavangerButton:
            startActivity(scavHuntIntent);
            break;
        case R.id.generalButton:
            startActivity(gInfoIntent);
            break;
        case R.id.donationsButton:
            startActivity(donationsIntent);
            break;

        case R.id.homeButton:
            startActivity(homeIntent);
            break;
        case R.id.animalsButton:
            startActivity(animalsIntent);
            break;
        case R.id.mapButton:
            startActivity(mapIntent);
            break;
        case R.id.socialButton:
            startActivity(socialIntent);
            break;

        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_scav_hunt, menu);
        return true;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // Check if the key event was the Back button and if there's history
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webQuiz.canGoBack()) {
            webQuiz.goBack();
            return true;
        }
        // If it wasn't the Back key or there's no web page history, bubble up to the default
        // system behavior (probably exit the activity)
        return super.onKeyDown(keyCode, event);
    }

}
这是我的XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ScavHuntActivity" >

   <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="bottom"
            android:maxHeight="75dp"
            android:weightSum="4" >

            <Button
                android:id="@+id/homeButton"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginBottom="0dp"
                android:layout_marginLeft="0dp"
                android:layout_marginRight="0dp"
                android:layout_marginTop="0dp"
                android:layout_weight="1"
                android:background="@color/beige"
                android:gravity="top|left"
                android:minHeight="75dp"
                android:minWidth="75dp"
                android:text="@string/home"
                android:textColor="@color/white"
                android:textSize="20sp" />

            <Button
                android:id="@+id/animalsButton"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginBottom="0dp"
                android:layout_marginLeft="0dp"
                android:layout_marginRight="0dp"
                android:layout_marginTop="0dp"
                android:layout_weight="1"
                android:background="@color/Yay"
                android:gravity="top|left"
                android:minHeight="75dp"
                android:minWidth="75dp"
                android:text="@string/animals"
                android:textColor="@color/white"
                android:textSize="20sp" />

            <Button
                android:id="@+id/scavangerButton"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginBottom="0dp"
                android:layout_marginLeft="0dp"
                android:layout_marginRight="0dp"
                android:layout_marginTop="0dp"
                android:layout_weight="1"
                android:background="@color/Yo"
                android:ellipsize="none"
                android:gravity="top|left"
                android:maxLines="100"
                android:minHeight="75dp"
                android:minWidth="75dp"
                android:scrollHorizontally="false"
                android:text="@string/scavanger_hunt"
                android:textColor="@color/white"
                android:textSize="16sp" />

            <Button
                android:id="@+id/eventsButton"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginBottom="0dp"
                android:layout_marginLeft="0dp"
                android:layout_marginRight="0dp"
                android:layout_marginTop="0dp"
                android:layout_weight="1"
                android:background="@color/green"
                android:gravity="top|left"
                android:minHeight="75dp"
                android:minWidth="75dp"
                android:text="@string/events"
                android:textColor="@color/white"
                android:textSize="20sp" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="top"
            android:minHeight="75dp"
            android:weightSum="4" >

            <Button
                android:id="@+id/mapButton"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginBottom="0dp"
                android:layout_marginLeft="0dp"
                android:layout_marginRight="0dp"
                android:layout_marginTop="0dp"
                android:layout_weight="1"
                android:background="@color/lightGreen"
                android:gravity="top|left"
                android:minHeight="75dp"
                android:text="@string/map"
                android:textColor="@color/white"
                android:textSize="20sp" />

            <Button
                android:id="@+id/generalButton"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginBottom="0dp"
                android:layout_marginLeft="0dp"
                android:layout_marginRight="0dp"
                android:layout_marginTop="0dp"
                android:layout_weight="1"
                android:background="@color/haha"
                android:ellipsize="none"
                android:gravity="top|left"
                android:maxLines="100"
                android:minHeight="75dp"
                android:scrollHorizontally="false"
                android:text="@string/general_information"
                android:textColor="@color/white"
                android:textSize="20sp" />

            <Button
                android:id="@+id/donationsButton"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginBottom="0dp"
                android:layout_marginLeft="0dp"
                android:layout_marginRight="0dp"
                android:layout_marginTop="0dp"
                android:layout_weight="1"
                android:background="@color/bla"
                android:ellipsize="none"
                android:gravity="top|left"
                android:maxLines="100"
                android:minHeight="75dp"
                android:minWidth="75dp"
                android:scrollHorizontally="false"
                android:text="@string/donations"
                android:textColor="@color/white"
                android:textSize="16sp" />

            <Button
                android:id="@+id/socialButton"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginBottom="0dp"
                android:layout_marginLeft="0dp"
                android:layout_marginRight="0dp"
                android:layout_marginTop="0dp"
                android:layout_weight="1"
                android:background="@color/meh"
                android:gravity="top|left"
                android:minHeight="75dp"
                android:text="@string/social"
                android:textColor="@color/white"
                android:textSize="20sp" />

        </LinearLayout>
    </LinearLayout>

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/linearLayout1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/otter" >

        <WebView
            android:id="@+id/webViewQuiz"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </FrameLayout>

</RelativeLayout>

尝试删除此行
view.loadUrl(url);view.loadUrl(“javascript:window.location.reload(true)”
和change
返回false
to
返回true