コード例 #1
0
 public void Init()
 {
     PersistentDataPath = Application.get_persistentDataPath();
     UnityVersion       = Application.get_unityVersion();
     if (InternalSDKUtils.IsAndroid)
     {
         PlatformVersion = AndroidInterop.GetStaticJavaField <string>("android.os.Build$VERSION", "RELEASE");
         Platform        = "Android";
         Model           = AndroidInterop.GetStaticJavaField <string>("android.os.Build", "MODEL");
         Make            = AndroidInterop.GetStaticJavaField <string>("android.os.Build", "MANUFACTURER");
         object javaObjectStatically = AndroidInterop.GetJavaObjectStatically("java.util.Locale", "getDefault");
         Locale = AndroidInterop.CallMethod <string>(javaObjectStatically, "toString", new object[0]);
         object androidContext = AndroidInterop.GetAndroidContext();
         PackageName = AndroidInterop.CallMethod <string>(androidContext, "getPackageName", new object[0]);
         object androidJavaObject  = AndroidInterop.CallMethod(androidContext, "getPackageManager");
         object androidJavaObject2 = AndroidInterop.CallMethod(androidJavaObject, "getPackageInfo", PackageName, 0);
         object obj = AndroidInterop.CallMethod(androidJavaObject, "getApplicationInfo", PackageName, 0);
         VersionCode = Convert.ToString(AndroidInterop.GetJavaField <int>(androidJavaObject2, "versionCode"));
         VersionName = AndroidInterop.GetJavaField <string>(androidJavaObject2, "versionName");
         Title       = AndroidInterop.CallMethod <string>(androidJavaObject, "getApplicationLabel", new object[1]
         {
             obj
         });
     }
     else if (InternalSDKUtils.IsiOS)
     {
         if (!string.IsNullOrEmpty(NSLocale.AutoUpdatingCurrentLocale.Identifier))
         {
             Locale = NSLocale.AutoUpdatingCurrentLocale.Identifier;
         }
         else
         {
             Locale = NSLocale.AutoUpdatingCurrentLocale.LocaleIdentifier;
         }
         using (UIDevice uIDevice = UIDevice.CurrentDevice)
         {
             Platform        = uIDevice.SystemName;
             PlatformVersion = uIDevice.SystemVersion;
             Model           = uIDevice.Model;
         }
         Make = "apple";
         using (NSBundle nSBundle = NSBundle.MainBundle)
         {
             using (NSDictionary nSDictionary = ThirdParty.iOS4Unity.Runtime.GetNSObject <NSDictionary>(ObjC.MessageSendIntPtr(nSBundle.Handle, Selector.GetHandle("infoDictionary"))))
             {
                 Title       = nSDictionary.ObjectForKey("CFBundleDisplayName").ToString();
                 VersionCode = nSDictionary.ObjectForKey("CFBundleVersion").ToString();
                 VersionName = nSDictionary.ObjectForKey("CFBundleShortVersionString").ToString();
                 PackageName = nSDictionary.ObjectForKey("CFBundleIdentifier").ToString();
             }
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Init this instance. This methods needs to be called from the main thread, Otherwise the values may not be initialized correctly
        /// </summary>
        public void Init()
        {
            PersistentDataPath = Application.persistentDataPath;

            UnityVersion = Application.unityVersion;

            if (InternalSDKUtils.IsAndroid)
            {
                //device related information
                PlatformVersion = AndroidInterop.GetStaticJavaField <string>("android.os.Build$VERSION", "RELEASE");
                Platform        = ANDROID_OS;
                Model           = AndroidInterop.GetStaticJavaField <string>("android.os.Build", "MODEL");

                Make = AndroidInterop.GetStaticJavaField <string>("android.os.Build", "MANUFACTURER");

                var locale = AndroidInterop.GetJavaObjectStatically("java.util.Locale", "getDefault");
                Locale = AndroidInterop.CallMethod <string>(locale, @"toString");

                //application related information
                var context = AndroidInterop.GetAndroidContext();
                PackageName = AndroidInterop.CallMethod <string>(context, "getPackageName");

                var packageManager  = AndroidInterop.CallMethod(context, "getPackageManager");
                var packageInfo     = AndroidInterop.CallMethod(packageManager, "getPackageInfo", PackageName, 0);
                var applicationInfo = AndroidInterop.CallMethod(packageManager, "getApplicationInfo", PackageName, 0);
                VersionCode = System.Convert.ToString(AndroidInterop.GetJavaField <int>(packageInfo, "versionCode"));
                VersionName = AndroidInterop.GetJavaField <string>(packageInfo, "versionName");
                Title       = AndroidInterop.CallMethod <string>(packageManager, "getApplicationLabel", applicationInfo);
            }
            else if (InternalSDKUtils.IsiOS)
            {
                //platform related information
                if (!string.IsNullOrEmpty(NSLocale.AutoUpdatingCurrentLocale.Identifier))
                {
                    Locale = NSLocale.AutoUpdatingCurrentLocale.Identifier;
                }
                else
                {
                    Locale = NSLocale.AutoUpdatingCurrentLocale.LocaleIdentifier;
                }

                using (var device = UIDevice.CurrentDevice)
                {
                    Platform        = device.SystemName;
                    PlatformVersion = device.SystemVersion;
                    Model           = device.Model;
                }

                Make = "apple";

                //Application related information
                using (var bundle = NSBundle.MainBundle)
                {
                    var infoPtr = ObjC.MessageSendIntPtr(bundle.Handle, Selector.GetHandle("infoDictionary"));
                    using (var info = ThirdParty.iOS4Unity.Runtime.GetNSObject <NSDictionary>(infoPtr))
                    {
                        Title       = info.ObjectForKey("CFBundleDisplayName").ToString();
                        VersionCode = info.ObjectForKey("CFBundleVersion").ToString();
                        VersionName = info.ObjectForKey("CFBundleShortVersionString").ToString();
                        PackageName = info.ObjectForKey("CFBundleIdentifier").ToString();
                    }
                }
            }
        }