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
I implemented in this form in webview using fragment- inside oncreate:
webView.setWebViewClient(new WebViewClient()
{
public boolean shouldOverrideUrlLoading(WebView viewx, String urlx)
{
if(Uri.parse(urlx).getHost().endsWith("facebook.com")) {
{
goToFacebook();
}
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlx));
viewx.getContext().startActivity(intent);
return true;
}
});
and outside onCreateView :
private void goToFacebook() {
try {
String facebookUrl = getFacebookPageURL();
Intent facebookIntent = new Intent(Intent.ACTION_VIEW);
facebookIntent.setData(Uri.parse(facebookUrl));
startActivity(facebookIntent);
} catch (Exception e) {
e.printStackTrace();
}
}
//facebook url load
private String getFacebookPageURL() {
String FACEBOOK_URL = "https://www.facebook.com/pg/XXpagenameXX/";
String facebookurl = null;
try {
PackageManager packageManager = getActivity().getPackageManager();
if (packageManager != null) {
Intent activated = packageManager.getLaunchIntentForPackage("com.facebook.katana");
if (activated != null) {
int versionCode = packageManager.getPackageInfo("com.facebook.katana", 0).versionCode;
if (versionCode >= 3002850) {
facebookurl = "fb://page/XXXXXXpage_id";
}
} else {
facebookurl = FACEBOOK_URL;
}
} else {
facebookurl = FACEBOOK_URL;
}
} catch (Exception e) {
facebookurl = FACEBOOK_URL;
}
return facebookurl;
}