Question by
tehrockman · Mar 06, 2018 at 12:41 AM ·
androidbuttonfacebookapp
,Hi guys, I need help setting an app button to get it to my facebook page.
,This is the code I have, but it gives me errors on the 8, 15 a 16 lines pointing the if, else and a primary constructor body not allowed, thanks in advance for your help.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FacebookLink : MonoBehaviour {
#if UNITY_ANDROID
if (checkPackageAppIsPresent("com.facebook.katana"))
{
Application.OpenURL("fb://page/xxxxxxxxxxxx");
//there is Facebook app installed so let's use it
}
else
{
Application.OpenURL("https://www.facebook.com/madebyonemstudio");
// no Facebook app - use built-in web browser
}
#endif
#if UNITY_ANDROID
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;
}
#endif
}
Comment