コード例 #1
0
    public static void UpdateManifest()
    {
        if (!GoogleMobileAdSettings.Instance.KeepManifestClean)
        {
            return;
        }

        SA.Manifest.Manager.Refresh();

        SA.Manifest.Template            Manifest         = SA.Manifest.Manager.GetManifest();
        SA.Manifest.ApplicationTemplate application      = Manifest.ApplicationTemplate;
        SA.Manifest.ActivityTemplate    launcherActivity = application.GetLauncherActivity();

        SA.Manifest.PropertyTemplate targetSdk = Manifest.GetOrCreatePropertyWithTag("uses-sdk");
        targetSdk.SetValue("android:targetSdkVersion", "26");

        SA.Manifest.ActivityTemplate AdActivity = application.GetOrCreateActivityWithName("com.google.android.gms.ads.AdActivity");
        AdActivity.SetValue("android:configChanges", "keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize");
        AdActivity.SetValue("android:theme", "@android:style/Theme.Translucent");

        if (launcherActivity != null)
        {
            SA.Manifest.PropertyTemplate ForwardNativeEventsToDalvik = launcherActivity.GetOrCreatePropertyWithName("meta-data", "unityplayer.ForwardNativeEventsToDalvik");
            ForwardNativeEventsToDalvik.SetValue("android:value", "true");
        }

        SA.Manifest.PropertyTemplate games_version = application.GetOrCreatePropertyWithName("meta-data", "com.google.android.gms.version");
                #if UNITY_4_6 || UNITY_4_7
        games_version.SetValue("android:value", GoogleMobileAdSettings.PLAY_SERVICE_VERSION_NUMBER);
                #else
        games_version.SetValue("android:value", "@integer/google_play_services_version");
                #endif

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

        SA.Manifest.Manager.Refresh();

        SA.Manifest.Template            Manifest         = SA.Manifest.Manager.GetManifest();
        SA.Manifest.ApplicationTemplate application      = Manifest.ApplicationTemplate;
        SA.Manifest.ActivityTemplate    launcherActivity = application.GetLauncherActivity();

        SA.Manifest.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)
        {
            SA.Manifest.PropertyTemplate intent_filter = AndroidNativeProxy.GetOrCreateIntentFilterWithName("android.intent.action.VIEW");
            AndroidNativeProxy.RemoveProperty(intent_filter);
        }

        SA.Manifest.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, SA.Manifest.ActivityTemplate> entry in application.Activities)
        {
            //TODO get intents array
            SA.Manifest.ActivityTemplate act    = entry.Value;
            SA.Manifest.PropertyTemplate intent = act.GetIntentFilterWithName("android.intent.action.VIEW");
            if (intent != null)
            {
                SA.Manifest.PropertyTemplate data = intent.GetOrCreatePropertyWithTag("data");
                if (data.GetValue("android:scheme") == "oauth")
                {
                    act.RemoveProperty(intent);
                }
            }
        }

        if (SocialPlatfromSettings.Instance.TwitterAPI)
        {
            if (SocialProxyActivity != null)
            {
                SA.Manifest.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");
                SA.Manifest.PropertyTemplate data = intent_filter.GetOrCreatePropertyWithTag("data");
                data.SetValue("android:scheme", "oauth");
                data.SetValue("android:host", PlayerSettings.bundleIdentifier);
            }
        }
        else
        {
            if (SocialProxyActivity != null)
            {
                SA.Manifest.PropertyTemplate intent_filter = SocialProxyActivity.GetOrCreateIntentFilterWithName("android.intent.action.VIEW");
                SocialProxyActivity.RemoveProperty(intent_filter);
            }
        }

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

        //This activity used for Facebook SDK v7.x
        SA.Manifest.ActivityTemplate FacebookActivity = application.GetOrCreateActivityWithName("com.facebook.FacebookActivity");

        if (Instalation.IsFacebookInstalled)
        {
                        #if UNITY_ANDROID
            string FBAppId = "0";
            try {
                ScriptableObject FB_Resourse = Resources.Load("FacebookSettings") as ScriptableObject;

                if (FB_Resourse != null)
                {
                    Type fb_settings = FB_Resourse.GetType();
                    System.Reflection.PropertyInfo propert = fb_settings.GetProperty("AppId", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
                    FBAppId = (string)propert.GetValue(null, null);
                }
            } catch (Exception ex) {
                Debug.LogError("AndroidNative. FBSettings.AppId reflection failed: " + ex.Message);
            }



            ApplicationId_meta.SetValue("android:value", "\\ " + FBAppId);

            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");

            if (SA.Common.Config.FB_SDK_MajorVersionCode >= 7)
            {
                FacebookActivity.SetValue("android:configChanges", "keyboard|keyboardHidden|screenLayout|screenSize|orientation");
                FacebookActivity.SetValue("android:theme", "@android:style/Theme.Translucent.NoTitleBar");
            }
            else
            {
                application.RemoveActivity(FacebookActivity);
            }
                        #endif
        }
        else
        {
            application.RemoveProperty(ApplicationId_meta);
            application.RemoveActivity(LoginActivity);
            application.RemoveActivity(FBUnityLoginActivity);
            application.RemoveActivity(FBUnityDeepLinkingActivity);
            application.RemoveActivity(FBUnityDialogsActivity);
            application.RemoveActivity(FacebookActivity);
        }


        ////////////////////////
        //NativeSharingAPI
        ////////////////////////
        SA.Manifest.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");
            SA.Manifest.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);
        }

        SA.Manifest.Manager.SaveManifest();
    }