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(); }
private static void ReadManifest(string manifestPath) { #if !(UNITY_WP8 || UNITY_METRO) //Read XML file _manifestTemplate = new AN_ManifestTemplate(); XmlDocument doc = new XmlDocument(); doc.Load(Application.dataPath + manifestPath); XmlNode rootNode = doc.DocumentElement; foreach (XmlAttribute attr in rootNode.Attributes) { _manifestTemplate.SetValue(attr.Name, attr.Value); } foreach (XmlNode childNode in rootNode.ChildNodes) { if (!childNode.Name.Equals("application") && !childNode.Name.Equals("uses-permission") && !childNode.Name.Equals("#comment")) { _manifestTemplate.AddProperty(childNode.Name, ParseProperty(childNode)); } } XmlNode applicationNode = null; foreach (XmlNode childNode in rootNode.ChildNodes) { if (childNode.Name.Equals("application")) { applicationNode = childNode; break; } } foreach (XmlAttribute attr in applicationNode.Attributes) { _manifestTemplate.ApplicationTemplate.SetValue(attr.Name, attr.Value); } foreach (XmlNode childNode in applicationNode.ChildNodes) { if (!childNode.Name.Equals("#comment") && !childNode.Name.Equals("activity")) { _manifestTemplate.ApplicationTemplate.AddProperty(childNode.Name, ParseProperty(childNode)); } } foreach (XmlNode childNode in applicationNode.ChildNodes) { if (childNode.Name.Equals("activity") && !childNode.Name.Equals("#comment")) { string activityName = ""; if (childNode.Attributes["android:name"] != null) { activityName = childNode.Attributes["android:name"].Value; } else { Debug.LogWarning("Android Manifest contains activity tag without android:name attribute."); } XmlNode launcher = null; bool isLauncher = false; foreach (XmlNode actNode in childNode.ChildNodes) { if (actNode.Name.Equals("intent-filter")) { foreach (XmlNode intentNode in actNode.ChildNodes) { if (intentNode.Name.Equals("category")) { if (intentNode.Attributes["android:name"].Value.Equals("android.intent.category.LAUNCHER")) { isLauncher = true; launcher = actNode; } } } } } AN_ActivityTemplate activity = new AN_ActivityTemplate(isLauncher, activityName); foreach (XmlAttribute attr in childNode.Attributes) { activity.SetValue(attr.Name, attr.Value); } foreach (XmlNode actNode in childNode.ChildNodes) { if (!actNode.Name.Equals("#comment")) { if (actNode != launcher) { activity.AddProperty(actNode.Name, ParseProperty(actNode)); } } } _manifestTemplate.ApplicationTemplate.AddActivity(activity); } } //Load Manifest Permissions foreach (XmlNode node in rootNode.ChildNodes) { if (node.Name.Equals("uses-permission")) { AN_PropertyTemplate permission = new AN_PropertyTemplate("uses-permission"); permission.SetValue("android:name", node.Attributes["android:name"].Value); _manifestTemplate.AddPermission(permission); } } #endif }
public static void UpdateManifest() { if (!AndroidNativeSettings.Instance.KeepManifestClean) { return; } AN_ManifestManager.Refresh(); int UpdateId = 0; AN_ManifestTemplate Manifest = AN_ManifestManager.GetManifest(); AN_ApplicationTemplate application = Manifest.ApplicationTemplate; AN_ActivityTemplate launcherActivity = application.GetLauncherActivity(); //////////////////////// //Google Play Service API //////////////////////// AN_PropertyTemplate games_version = application.GetOrCreatePropertyWithName("meta-data", "com.google.android.gms.version"); if (AndroidNativeSettings.Instance.EnablePSAPI) { games_version.SetValue("android:value", "@integer/google_play_services_version"); } else { application.RemoveProperty(games_version); } //////////////////////// //GooglePlayServicesAPI //////////////////////// UpdateId++; AN_PropertyTemplate games_APP_ID = application.GetOrCreatePropertyWithName("meta-data", "com.google.android.gms.games.APP_ID"); if (!AndroidNativeSettings.Instance.GooglePlayServicesAPI) { application.RemoveProperty(games_APP_ID); } else { games_APP_ID.SetValue("android:value", "@string/app_id"); } //////////////////////// //GoogleCloudSaveAPI //////////////////////// UpdateId++; AN_PropertyTemplate appstate_APP_ID = application.GetOrCreatePropertyWithName("meta-data", "com.google.android.gms.appstate.APP_ID"); if (AndroidNativeSettings.Instance.GoogleCloudSaveAPI) { appstate_APP_ID.SetValue("android:value", "@string/app_id"); AndroidNativeSettings.Instance.EnableAppStateAPI = true; } else { AndroidNativeSettings.Instance.EnableAppStateAPI = false; application.RemoveProperty(appstate_APP_ID); } //////////////////////// //AnalyticsAPI //////////////////////// UpdateId++; if (AndroidNativeSettings.Instance.AnalyticsAPI) { //Nothing to do } //////////////////////// //PushNotificationsAPI //////////////////////// UpdateId++; AN_PropertyTemplate GcmBroadcastReceiver = application.GetOrCreatePropertyWithName("receiver", "com.androidnative.gcm.GcmBroadcastReceiver"); AN_PropertyTemplate GcmIntentService = application.GetOrCreatePropertyWithName("service", "com.androidnative.gcm.GcmIntentService"); AN_PropertyTemplate permission_C2D_MESSAGE = Manifest.GetOrCreatePropertyWithName("permission", "com.example.gcm.permission.C2D_MESSAGE"); if (AndroidNativeSettings.Instance.PushNotificationsAPI) { GcmBroadcastReceiver.SetValue("android:permission", "com.google.android.c2dm.permission.SEND"); AN_PropertyTemplate intent_filter = GcmBroadcastReceiver.GetOrCreateIntentFilterWithName("com.google.android.c2dm.intent.RECEIVE"); AN_PropertyTemplate category = intent_filter.GetOrCreatePropertyWithTag("category"); category.SetValue("android:name", PlayerSettings.bundleIdentifier); permission_C2D_MESSAGE.SetValue("android:protectionLevel", "signature"); } else { application.RemoveProperty(GcmBroadcastReceiver); application.RemoveProperty(GcmIntentService); Manifest.RemoveProperty(permission_C2D_MESSAGE); } //////////////////////// //GoogleMobileAdAPI //////////////////////// UpdateId++; AN_ActivityTemplate AdActivity = application.GetOrCreateActivityWithName("com.google.android.gms.ads.AdActivity"); if (AndroidNativeSettings.Instance.GoogleMobileAdAPI) { if (launcherActivity != null) { AN_PropertyTemplate ForwardNativeEventsToDalvik = launcherActivity.GetOrCreatePropertyWithName("meta-data", "unityplayer.ForwardNativeEventsToDalvik"); ForwardNativeEventsToDalvik.SetValue("android:value", "true"); } AdActivity.SetValue("android:configChanges", "keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"); } else { application.RemoveActivity(AdActivity); } //////////////////////// //GoogleButtonAPI //////////////////////// UpdateId++; if (AndroidNativeSettings.Instance.GoogleButtonAPI) { //Nothing to do } //////////////////////// //LocalNotificationsAPI //////////////////////// AN_PropertyTemplate LocalNotificationReceiver = application.GetOrCreatePropertyWithName("receiver", "com.androidnative.features.notifications.LocalNotificationReceiver"); if (AndroidNativeSettings.Instance.LocalNotificationsAPI) { } else { application.RemoveProperty(LocalNotificationReceiver); } //////////////////////// //ImmersiveModeAPI //////////////////////// if (AndroidNativeSettings.Instance.ImmersiveModeAPI) { //Nothing to do } //////////////////////// //ApplicationInformationAPI //////////////////////// if (AndroidNativeSettings.Instance.ApplicationInformationAPI) { //Nothing to do } //////////////////////// //ExternalAppsAPI //////////////////////// if (AndroidNativeSettings.Instance.ExternalAppsAPI) { //Nothing to do } //////////////////////// //PoupsandPreloadersAPI //////////////////////// if (AndroidNativeSettings.Instance.PoupsandPreloadersAPI) { //Nothing to do } //////////////////////// //InAppPurchasesAPI //////////////////////// if (AndroidNativeSettings.Instance.InAppPurchasesAPI) { //Nothing to do } //////////////////////// //CameraAPI //////////////////////// if (AndroidNativeSettings.Instance.CameraAPI) { //Nothing to do } //////////////////////// //GalleryAPI //////////////////////// if (AndroidNativeSettings.Instance.GalleryAPI) { //Nothing to do } List <string> permissions = GetRequiredPermissions(); foreach (string p in permissions) { Manifest.AddPermission(p); } AN_ManifestManager.SaveManifest(); SocialPlatfromSettingsEditor.UpdateManifest(); }
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(); }
private static void ReadManifest(string manifestPath) { #if !(UNITY_WP8 || UNITY_METRO) //Read XML file _manifestTemplate = new AN_ManifestTemplate (); XmlDocument doc = new XmlDocument (); doc.Load (Application.dataPath + manifestPath); XmlNode rootNode = doc.DocumentElement; foreach (XmlAttribute attr in rootNode.Attributes) { _manifestTemplate.SetValue(attr.Name, attr.Value); } foreach (XmlNode childNode in rootNode.ChildNodes) { if (!childNode.Name.Equals("application") && !childNode.Name.Equals("uses-permission") && !childNode.Name.Equals("#comment")) { _manifestTemplate.AddProperty(childNode.Name, ParseProperty(childNode)); } } XmlNode applicationNode = null; foreach (XmlNode childNode in rootNode.ChildNodes) { if (childNode.Name.Equals("application")) { applicationNode = childNode; break; } } foreach (XmlAttribute attr in applicationNode.Attributes) { _manifestTemplate.ApplicationTemplate.SetValue(attr.Name, attr.Value); } foreach (XmlNode childNode in applicationNode.ChildNodes) { if(!childNode.Name.Equals("#comment") && !childNode.Name.Equals("activity")) { _manifestTemplate.ApplicationTemplate.AddProperty(childNode.Name, ParseProperty(childNode)); } } foreach (XmlNode childNode in applicationNode.ChildNodes) { if(childNode.Name.Equals("activity") && !childNode.Name.Equals("#comment")) { string activityName = ""; if(childNode.Attributes["android:name"] != null) { activityName = childNode.Attributes["android:name"].Value; } else { Debug.LogWarning("Android Manifest contains activity tag without android:name attribute."); } XmlNode launcher = null; bool isLauncher = false; foreach (XmlNode actNode in childNode.ChildNodes) { if (actNode.Name.Equals("intent-filter")) { foreach (XmlNode intentNode in actNode.ChildNodes) { if (intentNode.Name.Equals("category")) { if (intentNode.Attributes["android:name"].Value.Equals("android.intent.category.LAUNCHER")) { isLauncher = true; launcher = actNode; } } } } } AN_ActivityTemplate activity = new AN_ActivityTemplate(isLauncher, activityName); foreach (XmlAttribute attr in childNode.Attributes) { activity.SetValue(attr.Name, attr.Value); } foreach (XmlNode actNode in childNode.ChildNodes) { if (!actNode.Name.Equals("#comment")) { if (actNode != launcher) { activity.AddProperty(actNode.Name, ParseProperty(actNode)); } } } _manifestTemplate.ApplicationTemplate.AddActivity(activity); } } //Load Manifest Permissions foreach (XmlNode node in rootNode.ChildNodes) { if (node.Name.Equals("uses-permission")) { AN_PropertyTemplate permission = new AN_PropertyTemplate("uses-permission"); permission.SetValue("android:name", node.Attributes["android:name"].Value); _manifestTemplate.AddPermission(permission); } } #endif }