public static void UpdateManifest()
    {
        if (!SocialPlatfromSettings.Instance.KeepManifestClean)
        {
            return;
        }

        AN_ManifestManager.Refresh();

        AN_ManifestTemplate    Manifest         = AN_ManifestManager.GetManifest();
        AN_ApplicationTemplate application      = Manifest.ApplicationTemplate;
        AN_ActivityTemplate    launcherActivity = application.GetLauncherActivity();

        AN_ActivityTemplate AndroidNativeProxy = application.GetOrCreateActivityWithName("com.androidnative.AndroidNativeProxy");

        AndroidNativeProxy.SetValue("android:launchMode", "singleTask");
        AndroidNativeProxy.SetValue("android:label", "@string/app_name");
        AndroidNativeProxy.SetValue("android:configChanges", "fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen");
        AndroidNativeProxy.SetValue("android:theme", "@android:style/Theme.Translucent.NoTitleBar");

        // Remove VIEW intent filter from AndroidNativeProxy activity
        if (AndroidNativeProxy != null)
        {
            AN_PropertyTemplate intent_filter = AndroidNativeProxy.GetOrCreateIntentFilterWithName("android.intent.action.VIEW");
            AndroidNativeProxy.RemoveProperty(intent_filter);
        }

        AN_ActivityTemplate SocialProxyActivity = application.GetOrCreateActivityWithName("com.androidnative.features.social.common.SocialProxyActivity");

        SocialProxyActivity.SetValue("android:launchMode", "singleTask");
        SocialProxyActivity.SetValue("android:label", "@string/app_name");
        SocialProxyActivity.SetValue("android:configChanges", "fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen");
        SocialProxyActivity.SetValue("android:theme", "@android:style/Theme.Translucent.NoTitleBar");

        if (launcherActivity.Name == "com.androidnative.AndroidNativeBridge")
        {
            launcherActivity.SetName("com.unity3d.player.UnityPlayerNativeActivity");
        }


        ////////////////////////
        //TwitterAPI
        ////////////////////////


        foreach (KeyValuePair <int, AN_ActivityTemplate> entry in application.Activities)
        {
            //TODO get intents array
            AN_ActivityTemplate act    = entry.Value;
            AN_PropertyTemplate intent = act.GetIntentFilterWithName("android.intent.action.VIEW");
            if (intent != null)
            {
                AN_PropertyTemplate data = intent.GetOrCreatePropertyWithTag("data");
                if (data.GetValue("android:scheme") == "oauth")
                {
                    act.RemoveProperty(intent);
                }
            }
        }

        if (SocialPlatfromSettings.Instance.TwitterAPI)
        {
            if (SocialProxyActivity != null)
            {
                AN_PropertyTemplate intent_filter = SocialProxyActivity.GetOrCreateIntentFilterWithName("android.intent.action.VIEW");
                intent_filter.GetOrCreatePropertyWithName("category", "android.intent.category.DEFAULT");
                intent_filter.GetOrCreatePropertyWithName("category", "android.intent.category.BROWSABLE");
                AN_PropertyTemplate data = intent_filter.GetOrCreatePropertyWithTag("data");
                data.SetValue("android:scheme", "oauth");
                data.SetValue("android:host", PlayerSettings.bundleIdentifier);
            }
        }
        else
        {
            if (SocialProxyActivity != null)
            {
                AN_PropertyTemplate intent_filter = SocialProxyActivity.GetOrCreateIntentFilterWithName("android.intent.action.VIEW");
                SocialProxyActivity.RemoveProperty(intent_filter);
            }
        }

        ////////////////////////
        //FB API
        ////////////////////////
        AN_PropertyTemplate ApplicationId_meta         = application.GetOrCreatePropertyWithName("meta-data", "com.facebook.sdk.ApplicationId");
        AN_ActivityTemplate LoginActivity              = application.GetOrCreateActivityWithName("com.facebook.LoginActivity");
        AN_ActivityTemplate FBUnityLoginActivity       = application.GetOrCreateActivityWithName("com.facebook.unity.FBUnityLoginActivity");
        AN_ActivityTemplate FBUnityDeepLinkingActivity = application.GetOrCreateActivityWithName("com.facebook.unity.FBUnityDeepLinkingActivity");
        AN_ActivityTemplate FBUnityDialogsActivity     = application.GetOrCreateActivityWithName("com.facebook.unity.FBUnityDialogsActivity");


        if (IsFacebookInstalled)
        {
            ApplicationId_meta.SetValue("android:value", "\\ " + FBSettings.AppId);

            LoginActivity.SetValue("android:label", "@string/app_name");
            LoginActivity.SetValue("android:theme", "@android:style/Theme.Translucent.NoTitleBar");
            LoginActivity.SetValue("android:configChanges", "keyboardHidden|orientation");


            FBUnityLoginActivity.SetValue("android:theme", "@android:style/Theme.Translucent.NoTitleBar.Fullscreen");
            FBUnityLoginActivity.SetValue("android:configChanges", "fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen");

            FBUnityDialogsActivity.SetValue("android:theme", "@android:style/Theme.Translucent.NoTitleBar.Fullscreen");
            FBUnityDialogsActivity.SetValue("android:configChanges", "fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen");

            FBUnityDeepLinkingActivity.SetValue("android:exported", "true");
        }
        else
        {
            application.RemoveProperty(ApplicationId_meta);
            application.RemoveActivity(LoginActivity);
            application.RemoveActivity(FBUnityLoginActivity);
            application.RemoveActivity(FBUnityDeepLinkingActivity);
            application.RemoveActivity(FBUnityDialogsActivity);
        }


        ////////////////////////
        //NativeSharingAPI
        ////////////////////////
        AN_PropertyTemplate provider = application.GetOrCreatePropertyWithName("provider", "android.support.v4.content.FileProvider");

        if (SocialPlatfromSettings.Instance.NativeSharingAPI)
        {
#if !(UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6)
            //Remove FileProvider description from AndroidManifest.xml in Unity 5
            application.RemoveProperty(provider);
#else
            provider.SetValue("android:authorities", PlayerSettings.bundleIdentifier + ".fileprovider");
            provider.SetValue("android:exported", "false");
            provider.SetValue("android:grantUriPermissions", "true");
            AN_PropertyTemplate provider_meta = provider.GetOrCreatePropertyWithName("meta-data", "android.support.FILE_PROVIDER_PATHS");
            provider_meta.SetValue("android:resource", "@xml/file_paths");
#endif
        }
        else
        {
            application.RemoveProperty(provider);
        }


        List <string> permissions = GetRequiredPermissions();
        foreach (string p in permissions)
        {
            Manifest.AddPermission(p);
        }

        AN_ManifestManager.SaveManifest();
    }
Exemplo n.º 2
0
    public static void UpdateManifest()
    {
        if (!SocialPlatfromSettings.Instance.KeepManifestClean)
        {
            return;
        }

        AN_ManifestManager.Refresh();

        AN_ManifestTemplate    Manifest         = AN_ManifestManager.GetManifest();
        AN_ApplicationTemplate application      = Manifest.ApplicationTemplate;
        AN_ActivityTemplate    launcherActivity = application.GetLauncherActivity();


        ////////////////////////
        //TwitterAPI
        ////////////////////////
        foreach (KeyValuePair <int, AN_ActivityTemplate> entry in application.Activities)
        {
            //TODO get intents array
            AN_ActivityTemplate act    = entry.Value;
            AN_PropertyTemplate intent = act.GetIntentFilterWithName("android.intent.action.VIEW");
            if (intent != null)
            {
                AN_PropertyTemplate data = intent.GetPropertyWithTag("data");
                if (data.GetValue("android:scheme") == "oauth")
                {
                    act.RemoveProperty(intent);
                }
            }
        }

        if (SocialPlatfromSettings.Instance.TwitterAPI)
        {
            if (launcherActivity != null)
            {
                AN_PropertyTemplate intent_filter = launcherActivity.GetOrCreateIntentFilterWithName("android.intent.action.VIEW");
                intent_filter.GetOrCreatePropertyWithName("category", "android.intent.category.DEFAULT");
                intent_filter.GetOrCreatePropertyWithName("category", "android.intent.category.BROWSABLE");
                AN_PropertyTemplate data = intent_filter.GetOrCreatePropertyWithTag("data");
                data.SetValue("android:scheme", "oauth");
                data.SetValue("android:host", PlayerSettings.bundleIdentifier);
            }
        }
        else
        {
            if (launcherActivity != null)
            {
                AN_PropertyTemplate intent_filter = launcherActivity.GetOrCreateIntentFilterWithName("android.intent.action.VIEW");
                launcherActivity.RemoveProperty(intent_filter);
            }
        }

        ////////////////////////
        //FB API
        ////////////////////////
        AN_PropertyTemplate ApplicationId_meta         = application.GetOrCreatePropertyWithName("meta-data", "com.facebook.sdk.ApplicationId");
        AN_ActivityTemplate LoginActivity              = application.GetOrCreateActivityWithName("com.facebook.LoginActivity");
        AN_ActivityTemplate FBUnityLoginActivity       = application.GetOrCreateActivityWithName("com.facebook.unity.FBUnityLoginActivity");
        AN_ActivityTemplate FBUnityDeepLinkingActivity = application.GetOrCreateActivityWithName("com.facebook.unity.FBUnityDeepLinkingActivity");

        if (IsFacebookInstalled)
        {
            ApplicationId_meta.Value = "fb_app_id";
            LoginActivity.SetValue("android:label", "@string/app_name");
            LoginActivity.SetValue("android:theme", "@android:style/Theme.Translucent.NoTitleBar");
            FBUnityLoginActivity.SetValue("android:theme", "@android:style/Theme.Translucent.NoTitleBar.Fullscreen");
            FBUnityDeepLinkingActivity.SetValue("android:exported", "true");
        }
        else
        {
            application.RemoveProperty(ApplicationId_meta);
            application.RemoveActivity(LoginActivity);
            application.RemoveActivity(FBUnityLoginActivity);
            application.RemoveActivity(FBUnityDeepLinkingActivity);
        }


        ////////////////////////
        //NativeSharingAPI
        ////////////////////////
        AN_PropertyTemplate provider = application.GetOrCreatePropertyWithName("provider", "android.support.v4.content.FileProvider");

        if (SocialPlatfromSettings.Instance.NativeSharingAPI)
        {
            provider.SetValue("android:authorities", PlayerSettings.bundleIdentifier + ".fileprovider");
            provider.SetValue("android:exported", "false");
            provider.SetValue("android:grantUriPermissions", "true");
            AN_PropertyTemplate provider_meta = provider.GetOrCreatePropertyWithName("meta-data", "android.support.FILE_PROVIDER_PATHS");
            provider_meta.SetValue("android:resource", "@xml/file_paths");
        }
        else
        {
            application.RemoveProperty(provider);
        }



        List <string> permissions = GetRequiredPermissions();

        foreach (string p in permissions)
        {
            Manifest.AddPermission(p);
        }

        AN_ManifestManager.SaveManifest();
    }