launch facebook app from other app
To just start the default Launcher Activity:
Intent intent = new Intent("android.intent.category.LAUNCHER");
intent.setClassName("com.facebook.katana", "com.facebook.katana.LoginActivity");
startActivity(intent);
I did some research, because I wanted to find this out :). I found some ways how to start different activities easily. But I can not guarantee that this will work after upgrades of facebook. I tested it with my current facebook app and it works. At least I tested it with "adb shell" using "am start .....".
Basic is:
String uri = "facebook://facebook.com/inbox";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
the facebook.com part is not checked. you can even type: "facebook://gugus.com/inbox" having the same effect.
How to do this in adb.
1. Start adb shell through console: "adb shell"
2. run: "am start -a android.intent.action.VIEW -d facebook://facebook.com/inbox"
this will start the inbox activity.
Here some Uris with examples. I think they speak for themselves what they do.
facebook://facebook.com/inbox
facebook://facebook.com/info?user=544410940 (id of the user. "patrick.boos" won't work)
facebook://facebook.com/wall
facebook://facebook.com/wall?user=544410940 (will only show the info if you have added it as friend. otherwise redirects to another activity)
facebook://facebook.com/notifications
facebook://facebook.com/photos
facebook://facebook.com/album
facebook://facebook.com/photo
facebook://facebook.com/newsfeed
there might be additianl parameters you can give to certain of those uris, but I have no time to go through all the code of those activities.
How did I do this? check out apktool.
Open Facebook app from other app
For the iphone, you can launch the Facebook app if installed by using a url starting with fb://
More information can be found here: http://iphonedevtools.com/?p=302 also here: http://wiki.akosma.com/IPhone_URL_Schemes#Facebook
Stolen from the above site:
- fb://profile – Open Facebook app to the user’s profile
- fb://friends – Open Facebook app to the friends list
- fb://notifications – Open Facebook app to the notifications list (NOTE: there appears to be a bug with this URL. The Notifications page opens. However, it’s not possible to navigate to anywhere else in the Facebook app)
- fb://feed – Open Facebook app to the News Feed
- fb://events – Open Facebook app to the Events page
- fb://requests – Open Facebook app to the Requests list
- fb://notes - Open Facebook app to the Notes page
- fb://albums – Open Facebook app to Photo Albums list
To Launch:
NSURL *theURL = [NSURL URLWithString:@"fb://<insert function here>"];
[[UIApplication sharedApplication] openURL:theURL];
Open Facebook page from Android app?
In Facebook version 11.0.0.11.23 (3002850) fb://profile/
and fb://page/
no longer work. I decompiled the Facebook app and found that you can use fb://facewebmodal/f?href=[YOUR_FACEBOOK_PAGE]
. Here is the method I have been using in production:
/**
* <p>Intent to open the official Facebook app. If the Facebook app is not installed then the
* default web browser will be used.</p>
*
* <p>Example usage:</p>
*
* {@code newFacebookIntent(ctx.getPackageManager(), "https://www.facebook.com/JRummyApps");}
*
* @param pm
* The {@link PackageManager}. You can find this class through {@link
* Context#getPackageManager()}.
* @param url
* The full URL to the Facebook page or profile.
* @return An intent that will open the Facebook page/profile.
*/
public static Intent newFacebookIntent(PackageManager pm, String url) {
Uri uri = Uri.parse(url);
try {
ApplicationInfo applicationInfo = pm.getApplicationInfo("com.facebook.katana", 0);
if (applicationInfo.enabled) {
// http://stackoverflow.com/a/24547437/1048340
uri = Uri.parse("fb://facewebmodal/f?href=" + url);
}
} catch (PackageManager.NameNotFoundException ignored) {
}
return new Intent(Intent.ACTION_VIEW, uri);
}
Open Facebook application from my app
Use fb://
.
canOpenURL
returns a BOOL
value indicating whether or not the URL’s scheme can be handled by some app installed on the device. If canOpenURL
returns YES
then the application is present on the device. If the user has Facebook installed on their device we open it. If the user does not have Facebook installed we open the page through a link, which will launch Safari.
// Check if FB app installed on device
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"fb://profile/355356557838717"]];
}
else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.facebook.com/DanielStormApps"]];
}
Check out iPhone URL Schemes for a list of what else you can achieve via URL Schemes.
Also, starting at iOS 9 you must include LSApplicationQueriesSchemes
in your info.plist
.
Open Facebook Page in Facebook App (if installed) on Android
"fb://page/
does not work with newer versions of the FB app. You should use fb://facewebmodal/f?href=
for newer versions.
This is a full fledged working code currently live in one of my apps:
public static String FACEBOOK_URL = "https://www.facebook.com/YourPageName";
public static String FACEBOOK_PAGE_ID = "YourPageName";
//method to get the right URL to use in the intent
public String getFacebookPageURL(Context context) {
PackageManager packageManager = context.getPackageManager();
try {
int versionCode = packageManager.getPackageInfo("com.facebook.katana", 0).versionCode;
if (versionCode >= 3002850) { //newer versions of fb app
return "fb://facewebmodal/f?href=" + FACEBOOK_URL;
} else { //older versions of fb app
return "fb://page/" + FACEBOOK_PAGE_ID;
}
} catch (PackageManager.NameNotFoundException e) {
return FACEBOOK_URL; //normal web url
}
}
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:
Intent facebookIntent = new Intent(Intent.ACTION_VIEW);
String facebookUrl = getFacebookPageURL(this);
facebookIntent.setData(Uri.parse(facebookUrl));
startActivity(facebookIntent);
That's all you need.
Correct way in 2018 to open Facebook app via website link?
I figured it out, hope it helps someone else.
If the device is Android, use:
fb://facewebmodal/
And if it's iOS, use:
fb://page/PAGEID
If you do it automatically you need to detect the device first and then redirect to the appropriate link.
Android open facebook page link in facebook app if installed ,
Using this code you can open user profile
public static void opneFacebookProfile(Activity activity, String id) {
Intent facebookIntent = new Intent(Intent.ACTION_VIEW);
String facebookUrl = getFacebookPageURL(activity, id);
facebookIntent.setData(Uri.parse(facebookUrl));
activity.startActivity(facebookIntent);
}
Related Topics
Android - Android.View.Inflateexception: Binary Xml File Line #8: Error Inflating Class Fragment
How to Send String from One Activity to Another
Set Icon For Android Application
How to Display a List View in an Android Alert Dialog
How to Get the Width and Height of an Android.Widget.Imageview
Android Spinner: Get the Selected Item Change Event
How to Delete an Sms in Android Before It Reaches the Inbox
Android Studio Add External Project to Build.Gradle
How to Include *.So Library in Android Studio
Check Android Application Is in Foreground or Not
Open Application After Clicking on Notification
How to View the SQLite Database on an Android Device
Android: Remove Left Margin from Actionbar's Custom Layout
Programmatically Go Back to the Previous Fragment in the Backstack
How to Encrypt and Decrypt File in Android
How to Determine Mime Type of File in Android
Why Does Android Webview Sporadically Not Sending My Session Cookie