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
Declare constants
private String FACEBOOK_URL="https://www.facebook.com/approids";
private String FACEBOOK_PAGE_ID="approids";
Declare Method
public String getFacebookPageURL(Context context) {
PackageManager packageManager = context.getPackageManager();
try {
int versionCode = packageManager.getPackageInfo("com.facebook.katana", 0).versionCode;
boolean activated = packageManager.getApplicationInfo("com.facebook.katana", 0).enabled;
if(activated){
if ((versionCode >= 3002850)) {
Log.d("main","fb first url");
return "fb://facewebmodal/f?href=" + FACEBOOK_URL;
} else {
return "fb://page/" + FACEBOOK_PAGE_ID;
}
}else{
return FACEBOOK_URL;
}
} catch (PackageManager.NameNotFoundException e) {
return FACEBOOK_URL;
}
}
Call Function
Intent facebookIntent = new Intent(Intent.ACTION_VIEW);
String facebookUrl = getFacebookPageURL(MainActivity.this);
facebookIntent.setData(Uri.parse(facebookUrl));
startActivity(facebookIntent);