Open Facebook Page in Facebook App (If Installed) on Android

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 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.

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);
}

How to open profile on Facebook app from Android app

I think You do not declare your context in main body, You have to add,

context=getApplicationContext(); 

or

context=YourActivity.this;

to your body.

This is worked for me.

Button btn;
Context context;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn=(Button)findViewById(R.id.btn);
context=getApplicationContext();
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isAppInstalled()) {
Toast.makeText(getApplicationContext(), "facebook app already installed", Toast.LENGTH_SHORT).show();
Intent facebookIntent = new Intent(Intent.ACTION_VIEW);
String facebookUrl = getFacebookPageURL(context);
facebookIntent.setData(Uri.parse(facebookUrl));
startActivity(facebookIntent);

} else {
Toast.makeText(getApplicationContext(), "facebook app not installing", Toast.LENGTH_SHORT).show();
}



}
});
}
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.orca", 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
}
}



public boolean isAppInstalled() {
try {
getApplicationContext().getPackageManager().getApplicationInfo("com.facebook.katana", 0);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}

}

How to open facebook profile/page from ImageButton (Android)

Facebook android app don't support implicit intent mechanism for this action since 1.9.11 version. Facebook now use the same iPhone scheme mechanism fb:// or facebook://to handle all actions mentioned here.

And here you can see that they support the fb and facebook scheme.

    <activity android:name="com.facebook.katana.IntentUriHandler">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="facebook" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="fb" />
</intent-filter>
</activity>

As per your requirement, this method will handle both scenarios. First it will check if the facebook app is installed otherwise it will open facebook profile page in browser.

public Intent getFBIntent(Context context, String facebookId) {

try {
// Check if FB app is even installed
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);

String facebookScheme = "fb://profile/" + facebookId;
return new Intent(Intent.ACTION_VIEW, Uri.parse(facebookScheme));
}
catch(Exception e) {

// Cache and Open a url in browser
String facebookProfileUri = "https://www.facebook.com/" + facebookId;
return new Intent(Intent.ACTION_VIEW, Uri.parse(facebookProfileUri));
}

return null;
}

In order to open the facebook app with a user profile all you need to do is:

Intent facebookIntent = getFBIntent(this, "2347633432");
startActivity(facebookIntent);

** EDIT **

This is how you can call the above method in your activity. That's it!

public class AboutActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);

ImageButton f = (ImageButton)findViewById(R.id.f_logo);
f.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
// Get the intent
Intent intent = getFBIntent(AboutActivity.this, "sarmad.waleed.7");

// Start the activity
if (intent != null)
startActivity(intent);
}
});
}

/**
* Get the facebook intent for the given facebook
* profile id. If the facebook app is installed, then
* it will open the facebook app. Otherwise, it will
* open the facebook profile page in browser.
*
* @return - the facebook intent
*/
private Intent getFBIntent(Context context, String facebookId) {

try {
// Check if FB app is even installed
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);

String facebookScheme = "fb://profile/" + facebookId;
return new Intent(Intent.ACTION_VIEW, Uri.parse(facebookScheme));
}
catch(Exception e) {

// Cache and Open a url in browser
String facebookProfileUri = "https://www.facebook.com/" + facebookId;
return new Intent(Intent.ACTION_VIEW, Uri.parse(facebookProfileUri));
}

return null;
}
}

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.

Flutter open facebook link in facebook app android & ios

I also used the solution from the link @ruelluna mentioned.

Per current version, the below code worked for me:

String fbProtocolUrl;
if (Platform.isIOS) {
fbProtocolUrl = 'fb://profile/page_id';
} else {
fbProtocolUrl = 'fb://page/page_id';
}

String fallbackUrl = 'https://www.facebook.com/page_name';

try {
bool launched = await launch(fbProtocolUrl, forceSafariVC: false);

if (!launched) {
await launch(fallbackUrl, forceSafariVC: false);
}
} catch (e) {
await launch(fallbackUrl, forceSafariVC: false);
}

Also, make sure Info.plist file contains the following:

 <array> 
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb[your_page_id]</string>
</array>
</dict>
</array>

You can take your_page_id from: https://findmyfbid.com/

Open facebook page in App not the browser

In general it may not be possible, check this thread:
https://android.stackexchange.com/questions/37549/force-link-to-open-in-app-not-my-default-browser

But if you really want to do it, you can follow the same principle as it is proposed on this URL:
Open Facebook page from Android app?

In short, try to build an URL of form: fb://profile/pageID. The point of building such URL is because of IntentFilter defined in Facebook app. I am not sure if it will work, but if there is no Facebook app installed this will probably fail.

That should work when you click on a link in browser. It may depend on a browser though.

Link to open facebook app if app exists, else webpage

Here are the couple of links where you can find your suitable answer:

First you need to check browser is in mobile device or in desktop then apply below link code as per your requirement. here is the browser detect link : - Detecting a mobile browser

1) http://findnerd.com/list/view/How-to-detect-if-an-app-is-installed-in-IOS-or-ANDROID-with-the-help-of-javascript-and-Deep-Linking/4287/

2) How to check if an app is installed from a web-page on an iPhone?

3) iPhone browser: Checking if iPhone app is installed from browser

Let me know if you still need anything else.



Related Topics



Leave a reply



Submit