2016-12-31 28 views

回答

0

請使用webview並加載您的fb網頁url。

在類文件中添加以下代碼在XML文件中

<WebView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/webview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
/> 

WebView browser = (WebView) findViewById(R.id.webview); 
browser.loadUrl("http://www.facebook.com/yourpage"); 
在Menifest

文件

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

我有嘗試,但它在移動視圖 –

+0

不可見我用這個網頁流量,但是當我在FB它傳遞到瀏覽器登錄,我的賬戶是在我的瀏覽器並不在我的應用 –

0

這部作品的最新版本:

    如果您有它安裝在您的手機

    public static Intent getOpenFacebookIntent(Context context) { 
    try { 
        context.getPackageManager().getPackageInfo("com.facebook.katana", 0); 
        return new Intent(Intent.ACTION_VIEW,   
        Uri.parse("fb://page/<id_here>")); 
        } catch (Exception e) { 
        return new Intent(Intent.ACTION_VIEW,  
    Uri.parse("https://www.facebook.com/<user_name_here>")); 
        } 
    } 
    

這將打開Facebook的應用程序:

  • 轉到https://graph.facebook.com/<user_name_here>https://graph.facebook.com/fsintents例如)
  • 複製您的ID
  • 使用此方法。否則,Facebook將在瀏覽器中打開。

  • +0

    開不,我想開我在我自己的應用程序的fb頁面不在我的瀏覽器或其他fb相關應用程序中 –

    0
    **Integrating Facebook page using webview within android application.** 
    
    1. Add a <WebView> element in layout where you want to display facebook page as below. 
    
    <WebView 
        android:id="@+id/webview" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"/> 
    
    2. Access a reference say facebookView in corresponding class for layout as below: 
    3. facebookView = (WebView) rootView.findViewById(R.id.webview); 
    4. Call below methods on facebookView object. 
    
    5. facebookView.setWebViewClient(new UriWebViewClient()); 
    facebookView.setWebChromeClient(new UriChromeClient()); 
    WebSettings webSettings = facebookView.getSettings(); 
    
    6. Call below methods on webSettings object. 
    
    7. webSettings.setUseWideViewPort(true); 
    webSettings.setJavaScriptEnabled(true); 
    webSettings.setAppCacheEnabled(true); 
    webSettings.setDomStorageEnabled(true); 
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true); 
    webSettings.setSupportMultipleWindows(true); 
    webSettings.setSupportZoom(true); 
    webSettings.setBuiltInZoomControls(true); 
    
    8. Create a string variable webcode representing HTML for Facebook page generated from Facebook page plugins https://developers.facebook.com/docs/plugins/page-plugin/. It will be something like 
    
    9. String webcode = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "\t<title>Page Title</title>\n" + "</head>\n" 
         + "<body>\n" + "\n" + "<div id=\"fb-root\"></div>\n" 
         + "<style>" 
         +".fb-page, .fb-page:before, .fb-page:after { background-color: red; }" 
         + "</style>" 
         + "<script>" 
         +"(function(d, s, id) {\n" 
         + " var js, fjs = d.getElementsByTagName(s)[0];\n" + " if (d.getElementById(id)) return;\n" 
         + " js = d.createElement(s); js.id = id;\n" 
         + " js.src = \"//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.10&appId=1338324869626677\";\n" 
         + " fjs.parentNode.insertBefore(js, fjs);\n" + "}(document, 'script', 'facebook-jssdk'));" 
         + "</script>\n" 
         + "\n" 
         + "<div class=\"fb-page\" data-href=\"https://www.facebook.com/rg1breathe\" data-tabs=\"timeline\" data-small-header=\"true\" data-show-facepile=\"false\" data-adapt-container-width=\"true\" data-hide-cover=\"false\"><blockquote cite=\"https://www.facebook.com/rg1breathe\" class=\"fb-xfbml-parse-ignore\"><a href=\"https://www.facebook.com/rg1breathe\">RoundGlass Breathe</a></blockquote></div>\n" 
         + "</body>\n" + "</html>"; 
    
    10. Call below method on facebookView object. 
    
    11. facebookView.loadDataWithBaseURL("https://www.facebook.com", webcode, "text/html", "utf-8", null); 
    
    12. Create UriWebViewClient and UriChromeClient as below : 
    
    private class UriWebViewClient extends WebViewClient { 
        @Override 
        public boolean shouldOverrideUrlLoading(WebView view, String url) { 
         return false; 
        } 
    
        @Override 
        public void onPageFinished(WebView view, String url) { 
         super.onPageFinished(view, url); 
         String host = Uri.parse(url).getHost(); 
         Log.d(TAG, "page finished url: " + url + ", host: " + host); 
         if (url.contains("/plugins/close_popup.php?reload")) { 
          final Handler handler = new Handler(); 
          handler.postDelayed(new Runnable() { 
           @Override 
           public void run() { 
            //Do something after 100ms 
            mContainer.removeView(mWebviewPop); 
            loadFacebookPage(); 
           } 
          }, 600); 
         } 
        } 
    
        @Override 
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { 
         Log.d("onReceivedSslError", "onReceivedSslError"); 
        } 
    } 
    class UriChromeClient extends WebChromeClient { 
    
        @Override 
        public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) { 
         Log.d("onCreateWindow", "called"); 
         mWebviewPop = new WebView(getActivity()); 
         setSettings(mWebviewPop.getSettings()); 
    
         view.setClickable(true); 
         mWebviewPop.setVerticalScrollBarEnabled(true); 
         mWebviewPop.setHorizontalScrollBarEnabled(true); 
         mWebviewPop.setWebViewClient(new UriWebViewClient()); 
         mWebviewPop.setWebChromeClient(this); 
         mWebviewPop.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 
           ViewGroup.LayoutParams.MATCH_PARENT)); 
         mContainer.addView(mWebviewPop); 
    
         mWebviewPop.requestFocus(); 
         facebookView.setVisibility(View.GONE); 
         WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj; 
         transport.setWebView(mWebviewPop); 
         resultMsg.sendToTarget(); 
         return true; 
        } 
    
        @Override 
        public boolean onConsoleMessage(ConsoleMessage cm) { 
         Log.d("WebViewDebug", cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId()); 
         return true; 
        } 
    
        @Override 
        public void onCloseWindow(WebView window) { 
         mContainer.removeViewAt(mContainer.getChildCount() - 1); 
         mWebviewPop = null; 
         facebookView.setVisibility(View.VISIBLE); 
         facebookView.requestFocus(); 
        } 
    } 
    
    相關問題