Hi Unitarians,
I have an android app, and I have a button that I want my users to click to go to my facebook page and like it. If I use Application.OpenURL("https://www.facebook.com/youthquality");
, then it goes through the browser, which isn’t ideal. I want it so that so it goes to the facebook app, if it is on the phone. I use the following code that works mostly:
void Facebook () {
#if UNITY_EDITOR
Application.OpenURL("https://www.facebook.com/xxx");
#elif UNITY_IPHONE
Debug.Log("Unity iPhone");
#else
if(checkPackageAppIsPresent("com.facebook.katana")) {
Application.OpenURL("fb://profile/xxx"); //there is Facebook app installed so let's use it
}
else {
Application.OpenURL("https://www.facebook.com/xxx"); // no Facebook app - use built-in web browser
}
#endif
}
private bool checkPackageAppIsPresent(string package)
{
AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
//take the list of all packages on the device
AndroidJavaObject appList = packageManager.Call<AndroidJavaObject>("getInstalledPackages",0);
int num = appList.Call<int>("size");
for(int i = 0; i < num; i++)
{
AndroidJavaObject appInfo = appList.Call<AndroidJavaObject>("get", i);
string packageNew = appInfo.Get<string>("packageName");
if(packageNew.CompareTo(package) == 0)
{
return true;
}
}
return false;
}
The problem with the code is that it opens the facebook app, but it goes tot he newsfeed, and not to my page. How would I make it go to my page?
My actual page has a set name that I put, not numbers. It is not a profile, it is a page.