facebook上的facebook就像登录后显示空白屏幕

时间:2014-01-07 06:30:35

标签: android facebook facebook-like

我利用我的应用程序的facebook html打开像这样https://developers.facebook.com/docs/plugins/like-button/

的网页浏览

webview显示了一个Like和Share按钮,但在我登录facebook后,它不会返回到Like and Share按钮,但是一个空白页面,分享按钮工作正常。

那么登录后如何像url一样返回facebook?

public class LikeFacebookActivity extends BaseActivity {

    private WebView webView;
    private final String URL = "facebookIDhere";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.like_facebook_webview);

        webView = (WebView) findViewById(R.id.webView1);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setAppCacheEnabled(true);
        webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

        showLoading();
        webView.setWebViewClient(new MyWebViewClient());

        webView.loadUrl(URL);


        ActionBar actionbar = getActionBar();
        actionbar.setCustomView(R.layout.actionbar_top_like_facebook);
        actionbar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

        Button backButton = (Button) findViewById(R.id.buttonGeneralBack);

        backButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }

    @Override
    public void onBackPressed() {
        finish();
        overridePendingTransition(R.anim.animation_slide_from_left,
                R.anim.animation_slide_to_right);
    }

    public class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {         
            if(url.contains("something")) return true;
            return false; 
        }
        public void onPageFinished(WebView view, String url) {
            hideLoading();
        }
    }

}

1 个答案:

答案 0 :(得分:4)

我已经解决了这个问题,只需使用system.out.println来查看facebook在登录后加载哪个页面

public class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {         
        if(url.contains("something")) return true;
        return false; //Default is to not override unless our condition is met.
    }
    public void onPageFinished(WebView view, String url) {
        hideLoading();
        //String webUrl = webView.getUrl();
        //System.out.println(webUrl);
        if(url.startsWith("https://www.facebook.com/plugins/close_popup.php#_=_")){
            String redirectUrl = URL;
             view.loadUrl(redirectUrl);
            return;
        }
         super.onPageFinished(view, url);
    }
}