2011-06-06 54 views
7

可能重複打開Facebook的應用程序:
Open Facebook page from Android app?URL在Android的

我在我的Android應用程序的WebView,我想提出一個鏈接中打開了Facebook應用程序到我的粉絲頁面。在iOS中,你可以說fb:// ...它將打開Facebook應用程序。有沒有辦法在android中做到這一點?我已經在重寫shouldOverrideUrlLoading,所以我可以攔截它並在需要時啓動一個intent。

回答

6

您需要使用Intents。以下是如何調用FB應用程序(如果已安裝):

Intent intent = new Intent(); 
intent.setClassName("com.facebook.katana","com.facebook.katana.ProxyAuth"); 
intent.putExtra("client_id", applicationId); 
mAuthActivityCode = activityCode; 
activity.startActivityForResult(intent, activityCode); 

此代碼取自授權操作的Facebook API。 Ajust以滿足您的需求。代碼是版權所有2010 Facebook,Inc.,根據Apache許可證2.0版許可。

+0

謝謝,我已經幾乎得到它的工作。我不確定活動代碼是什麼。併爲應用程序ID是我的粉絲頁面ID?我似乎無法找到非常好的文檔。 – mouser58907 2011-06-06 21:05:28

+0

試試這裏提供的代碼:http://stackoverflow.com/questions/4810803/open-facebook-page-from-android-app/4814030#4814030 – 2011-06-06 22:01:12

0
myWebView = (WebView) findViewById(R.id.webview); // Create an instance of WebView and set it to the layout component created with id webview in main.xml 
     myWebView.getSettings().setJavaScriptEnabled(true); 
     myWebView.loadUrl("http://m.facebook.com/pages/xxxxx-xxxxx-xxxxx/xxxxxxxxxx"); // Specify the URL to load when the application starts 
     //myWebView.loadUrl("file://sdcard/"); // Specify a local file to load when the application starts. Will only load file types WebView supports 
     myWebView.setWebViewClient(new WebViewKeep()); 
     myWebView.setInitialScale(1); // Set the initial zoom scale 
     myWebView.getSettings().setBuiltInZoomControls(true); // Initialize zoom controls for your WebView component 
     myWebView.getSettings().setUseWideViewPort(true); // Initializes double-tap zoom control 

檢查是否適用於您。