from my Android app, I would like to open a link to a Facebook profile in the official Facebook app (if the app is installed, of course). For iPhone, there exists the fb://
URL scheme, but trying the same thing on my Android device throws an ActivityNotFoundException
.
Is there a chance to open a Facebook profile in the official Facebook app from code?
This works on the latest version:
Use this method:
This will open the Facebook app if the user has it installed. Otherwise, it will open Facebook in the browser.
EDIT: since version 11.0.0.11.23 (3002850) Facebook App do not support this way anymore, there's another way, check the response below from Jared Rummler.
Is this not easier? For example within an onClickListener?
PS. Get your id (the large number) from http://graph.facebook.com/[userName]
For Facebook page:
For Facebook profile:
...because none of the answers points out the difference
Both tested with Facebook v.27.0.0.24.15 and Android 5.0.1 on Nexus 4
Here's the way to do it in 2016, works great, and is very easy.
I discovered this after looking into how emails send by facebook opened the app.
My answer builds on top of the widely-accepted answer from joaomgcd. If the user has Facebook installed but disabled (for example by using App Quarantine), this method will not work. The intent for the Twitter app will be selected but it will not be able to process it as it is disabled.
Instead of:
You can use the following to decide what to do:
"fb://page/
does not work with newer versions of the FB app. You should usefb://facewebmodal/f?href=
for newer versions.This is a full fledged working code:
This method will return the correct url for app if installed or web url if app is not installed.
Then start an intent as follows: