Android的无法在web视图来实现Facebook的评论,由于默认浏览器 [英] Android unable to implement facebook comment in a webview due to default browser

查看:219
本文介绍了Android的无法在web视图来实现Facebook的评论,由于默认浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,Android的发展,这种的WebView和WebView功能的客户端是我的命。这是我的情况:

I am newbie to Android development and this webview and webview client is killing me. This is my scenario:

  1. 我必须加载包含Facebook的社交插件(用于评论特定URL)的网页,我使用的WebView它
  2. 当用户点击使用Facebook的评论,他/她将被给予登录页面上相同的WebView(而不是打开默认的浏览器)
  3. 一旦登录成功,第一页(含社会插件的)要显示,允许用户发表评论

我所要做的就是模拟浏览器的工作过程,即在时,他/她将被自动授予的权限日志添加Facebook的评论的用户。

What I have to do is emulate the working process of browser i.e. the user when logs in, he/she is automatically granted permission to add facebook comment.

我的问题:

我不知道如何从浏览器中得到的所有验证和重定向回我的应用程序的WebView。我想是做所有的过程我的应用程序的WebView而不是去默认浏览器。

I don't know how to get all the authentication from browser and redirect it back to my app webview. What I want is to do all the process in my app webview rather than going to default browser.

我已经检查了所有堆栈溢出的问题,其中大部分提供建议使用开源的Facebook插件,像连接Facebook和Facebook的Andr​​oid SDK。而且我得到了 CookieManager CookieSyncManager WebViewClient 一些信息, WebChromeClient 但我不能对我的问题落实。而且我发现最接近的是这样的:

I have checked all the stack overflow questions and most of them advise on using open source Facebook plugins like Facebook connect and Facebook android SDK. Further I got some info on CookieManager, CookieSyncManager, WebViewClient, WebChromeClient but I couldn't implement on my issue. And the closest I found is this:

<一个href="http://stackoverflow.com/questions/7485850/how-to-handle-facebook-like-with-confirm-in-android-webview">How处理Facebook的喜欢与确认的Andr​​oid的WebView

所以人们,如果你可以点我在正确的方向,我会非常高兴。我还是想知道如何使一个web视图的所有行动,如果有的话来了,我肯定会发布。

So folks if you could point me in the right direction, I would be very glad. I am still trying to understand on how to make all the action on a webview and if anything comes I will surely post.

在此先感谢

更新

我只能实施的Facebook 登录,但无法实施 AOL 的Hotmail 雅虎登录。对于的Facebook 登录只需创建一个自定义WebViewClient和方法shouldOverrideUrlLoading

I could only implement facebook login but couldn't implement AOL,Hotmail and Yahoo login. For facebook login just create a custom WebViewClient and on method shouldOverrideUrlLoading

if(url.contains("https://www.facebook.com/connect/window_comm.php")){
    webView.clearHistory();
    webView.loadUrl(remoteUrl);
}
return false;

要允许多个登录我已经实现以下技术,但它不能正常工作

To allow multiple login I have implemented following technique but it doesn't work

 if(url.contains("https://www.facebook.com/connect/window_comm.php")){
    String cookieString = cookieManager.getCookie("facebook.com");
    if(cookieString != null){
      cookieManager.setCookie("remoteUrldomain.com", cookieString);
      CookieSyncManager.getInstance().sync();
      webView.clearHistory();
      webView.loadUrl(remoteUrl);
    }
}
return false;

我还是尽我所能找到的解决方案,而没有人在那里会指导我在正确的方向,将不胜感激。 在此先感谢

I am still doing my best to find the solution, and anybody out there would guide me in proper direction that would be grateful . Thanks in advance

推荐答案

提供的答案    <一href="http://stackoverflow.com/questions/7485850/how-to-handle-facebook-like-with-confirm-in-android-webview">How处理Facebook的喜欢与确认机器人的WebView 是我发现这样far.What我学到的最好的解决办法是,安卓 的WebView 默认不加载的HTML视图为此,我们需要使用弹出 WebChromeClient 处理所有these.Look在以下code

The answer provided on How to handle facebook like with confirm in android webview is the best solution I have found so far.What I learnt is that Android WebView doesn't by default load the popup of html views and for that we need to use WebChromeClient which handles all these.Look at the following code

 private String requestUrl="some web link containing facebook social comment";
 private WebView webView,childView =null;
 private LinearLayout parentLayout;
 private Activity MyActivity;
 @Override
 public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    this.getWindow().requestFeature(Window.FEATURE_PROGRESS);

    setContentView(R.layout.main);

    getWindow().setFeatureInt(Window.FEATURE_PROGRESS,Window.PROGRESS_VISIBILITY_ON);
    parentLayout =(LinearLayout)findViewById(R.id.parentLayout);


    MyActivity = this;


    webView = new WebView(this);
    webView.setLayoutParams(getLayoutParams());

    webView.setWebViewClient(new FaceBookClient());
    webView.setWebChromeClient(new MyChromeClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setAppCacheEnabled(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webView.getSettings().setSupportMultipleWindows(true);
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setBuiltInZoomControls(true);

    parentLayout.addView(webView);
    webView.loadUrl(requestUrl);

 }

  private LinearLayout.LayoutParams getLayoutParams(){
    return new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT); 
}


    final class MyChromeClient extends WebChromeClient{
    @Override
    public boolean onCreateWindow(WebView view, boolean dialog,
            boolean userGesture, Message resultMsg) {
        childView = new WebView(SmCommentTestActivity.this);
        childView.getSettings().setJavaScriptEnabled(true);
        childView.getSettings().setSupportZoom(true);
        childView.getSettings().setBuiltInZoomControls(true);
        childView.setWebViewClient(new FaceBookClient());
        childView.setWebChromeClient(this);
        childView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));


        parentLayout.addView(childView);


        childView.requestFocus();
        webView.setVisibility(View.GONE);

          /*I think this is the main part which handles all the log in session*/
        WebView.WebViewTransport transport =(WebView.WebViewTransport)resultMsg.obj;
        transport.setWebView(childView);
        resultMsg.sendToTarget();
        return true;
    }


    @Override
    public void onProgressChanged(WebView view, int newProgress) {
        MyActivity.setProgress(newProgress*100);
    }

    @Override
    public void onCloseWindow(WebView window) {
        parentLayout.removeViewAt(parentLayout.getChildCount()-1);
        childView =null;
        webView.setVisibility(View.VISIBLE);
        webView.requestFocus();
    }
}

    private class FaceBookClient extends WebViewClient{
     @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        Log.i("REQUEST URL",url);
        return false;
    }   
}

    @Override
    public void onBackPressed() {
    if(childView != null && parentLayout.getChildCount()==2){
        childView.stopLoading();
        parentLayout.removeViewAt(parentLayout.getChildCount()-1);
        if(webView.getVisibility() == View.GONE)
            webView.setVisibility(View.VISIBLE);
    }else{          
        super.onBackPressed();
    }
}

这是所有的人有做实施 Facebook的社会化评论插件的Andr​​oid的WebView ,如果有人发现任何瑕疵,那么我会很乐意更正it.And希望,这种解决方案能够节省和时间对任何陷入困境的开发商和我一样;)

This is all one has to do to implement Facebook Social Comment Plugin on Android WebView and if somebody finds any flaw in it,then I would be happy to correct it.And hope,this solution would save and time on any troubled developer like me ;)

这篇关于Android的无法在web视图来实现Facebook的评论,由于默认浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆