如何关闭URL上的WebView更改

时间:2013-12-04 07:15:07

标签: android facebook webview

我知道我问了很多次,但我仍然无法关闭webview,它仍然会重定向到facebook家。

public class FBShareAll extends Activity {

private WebView webView;
String testAddress = "some string";
String myUrl;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fbshare_all);
    webView = (WebView) findViewById(R.id.webView1);


    Intent get = getIntent();
    final String QC = get.getExtras().getString("QC");
    webView.getSettings().setJavaScriptEnabled(true); 
    webView.setWebViewClient(new MyWebViewClient());
    if(QC.equals("Google")){


         String title = "Quezon City Guide";
            String desc = "Your Number One City Guide!";
            String image = "http://s21.postimg.org/6sq49njub/launchertrans.png";

            testAddress ="http://www.facebook.com/sharer.php?m2w&s=100&p[title]="+title+"&p[summary]="+desc+"&p[url]=http://www.sample.com&p[images][0]="+image;

        if(myUrl == null){
            myUrl = testAddress;
        }
        webView.loadUrl(myUrl);

    }




}

private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        myUrl = url;



        if(myUrl.equals("http://m.facebook.com/?_rdr")){
            ViewGroup vg = (ViewGroup)webView.getParent();
            if(vg != null)
               vg.removeView(webView);
            webView.setVisibility(View.GONE);
            finish();
        }



   //   else 
            view.loadUrl(url);

        Log.i("URL", myUrl);

        if(myUrl.equals("http://m.facebook.com/?_rdr")){
            ViewGroup vg = (ViewGroup)webView.getParent();
            if(vg != null)
               vg.removeView(webView);
            webView.setVisibility(View.GONE);
            finish();
        }

        return true;
 }


}

public void onPause(){
    super.onPause();
    finish();
 }


public void onRestart(){
    super.onRestart();
    finish();
    }

    }

如果我这样做,它只会关闭webview。

if(myUrl.equals(url)){
  finish();
 }

我不知道为什么只有在检测到原始网址时才会关闭。有人可以帮忙吗?谢谢!

0 个答案:

没有答案