Reputation: 385
I've looked for a while on the internet, but haven't found a solution yet.
So my question is : Is it possible to open a facebook page 'x' in the facebook app, from clicking on a listitem in my own android app?
Because now i'm linking to the fb page 'x' in my app in a webview, and it would be better to open the fb app and directly go to the page 'x'.
EDIT i have found a solution, but it is not working completely yet. it opens the facebook app now, but as the page that I want to display is not a profile but a page it gives an error in the facebook app. here is the code:
public static Intent getOpenFacebookIntent(Context context) {
try {
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/androiddevs"));
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/androiddevs"));
}
}
this does'nt work. if i edit the first URI parse to
Uri.parse("fb://profile/myprofileid")
then I am able to open my profile in the app. but the page I want to display is not my own page. And I could ask them info,if nesecaraly, as I know the people.
but maybe someone has some idea to get this to work.
Upvotes: 0
Views: 3872
Reputation: 385
Ok so I solved it eventually.
This is the Working Code:
public static Intent getOpenFacebookIntent(Context context) {
try {
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/5676133521"));
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://touch.facebook.com/androiddevs"));
}
}
}
to obtain the ID of a page you just go to the page in facebook in your browser, and then replace the 'www' to 'graph'. the firs line you'll see will be the ID of the page.
hope this helps people who have the same problem i had !
Upvotes: 6