8

Possible Duplicate:
Open Facebook page from Android app?

I have a webview in my android app, and I would like to put a link in that opens the facebook app to my fanpage. In iOS you can say fb://... and it will open the facebook app. Is there a way to do it in android? I'm already overriding shouldOverrideUrlLoading, so I could intercept it and launch an intent if I need to.

Community
  • 1
  • 1
mouser58907
  • 797
  • 2
  • 10
  • 21

2 Answers2

6

You need to use Intents. Here's how to call the FB application (if it is installed):

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

This code is taken from the Facebook API, which authorizes an action. Ajust to suit your needs. Code is Copyright 2010 Facebook, Inc., licensed under the Apache License, Version 2.0.

Amandeep Grewal
  • 1,801
  • 3
  • 19
  • 30
  • thanks, I've almost got it working. I'm not sure what the activity codes are though. and for application ID is that my fan page id? I can't seem to find very good documentation on this. – mouser58907 Jun 06 '11 at 21:05
  • Try the code presented here: http://stackoverflow.com/questions/4810803/open-facebook-page-from-android-app/4814030#4814030 – Amandeep Grewal Jun 06 '11 at 22:01
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

Check if this works for you.

Christopher
  • 25
  • 1
  • 2
  • 9