Exemple #1
0
        public String GetUniqueID()
        {
            AndroidJavaClass unityPlayer = PlatformIntegrationUtil.GetAndroidJavaClass("com.unity3d.player.UnityPlayer");

            if (unityPlayer == null)
            {
                Logger.Log("Can't get UnityPlayer");
                return(null);
            }

            AndroidJavaObject activity = PlatformIntegrationUtil.GetStatic <AndroidJavaObject>(unityPlayer, "currentActivity");

            if (activity == null)
            {
                Logger.Log("Can't find an activity!");
                return(null);
            }

            AndroidJavaObject context = PlatformIntegrationUtil.Call <AndroidJavaObject>(activity, "getApplicationContext");

            if (context == null)
            {
                Logger.Log("Can't find an app context!");
                return(null);
            }

            AndroidJavaObject contentResolver = PlatformIntegrationUtil.Call <AndroidJavaObject>(context, "getContentResolver");

            if (contentResolver == null)
            {
                Logger.Log("Can't get content resolver from context");
                return(null);
            }

            AndroidJavaClass secureClass = PlatformIntegrationUtil.GetAndroidJavaClass("android.provider.Settings$Secure");

            if (secureClass == null)
            {
                Logger.Log("Can't get secure class");
                return(null);
            }

            AndroidJavaObject androidID = PlatformIntegrationUtil.GetStatic <AndroidJavaObject>(secureClass, "ANDROID_ID");

            if (androidID == null)
            {
                Logger.Log("Cant get Android ID static string");
                return(null);
            }

            object[] parameters = new object[2];
            parameters[0] = contentResolver;
            parameters[1] = androidID;

            string aid = PlatformIntegrationUtil.CallStatic <string>(secureClass, "getString", parameters);

            if (aid != null)
            {
                string hashedAdId = HexUtil.HexStringSha512(aid);
                return(hashedAdId);
            }
            return(aid);
        }
        public AndroidJavaObject GetTelephonyManager()
        {
            AndroidJavaClass unityPlayer = PlatformIntegrationUtil.GetAndroidJavaClass("com.unity3d.player.UnityPlayer");

            if (unityPlayer == null)
            {
                Logger.Log("Unable to get UnityPlayer");
                return(null);
            }
            AndroidJavaObject activity = PlatformIntegrationUtil.GetStatic <AndroidJavaObject>(unityPlayer, "currentActivity");

            if (activity == null)
            {
                Logger.Log("Can't find an activity!");
                return(null);
            }

            AndroidJavaObject context = PlatformIntegrationUtil.Call <AndroidJavaObject>(activity, "getApplicationContext");

            if (context == null)
            {
                Logger.Log("Can't find an app context!");
                return(null);
            }

            // Context.TELEPHONY_SERVICE:
            string CONTEXT_TELEPHONY_SERVICE = context.GetStatic <string>("TELEPHONY_SERVICE");

            if (CONTEXT_TELEPHONY_SERVICE == null)
            {
                Logger.Log("Can't get Context Telephony Service");
                return(null);
            }

            AndroidJavaObject telManager = PlatformIntegrationUtil.Call <AndroidJavaObject>(context, "getSystemService", new object[] { CONTEXT_TELEPHONY_SERVICE });

            sdkVersion = getAndroidSDKVers();

            if (sdkVersion < 24)
            {
                return(telManager);
            }

            // Call SubscriptionManager to get a specific telManager:
            AndroidJavaClass subscriptionManagerCls = PlatformIntegrationUtil.GetAndroidJavaClass("android.telephony.SubscriptionManager");

            if (subscriptionManagerCls == null)
            {
                Logger.Log("Can't get Subscription Manager Class.");
                return(null);
            }
            int subId        = PlatformIntegrationUtil.CallStatic <int>(subscriptionManagerCls, "getDefaultDataSubscriptionId");
            int invalidSubId = PlatformIntegrationUtil.GetStatic <int>(subscriptionManagerCls, "INVALID_SUBSCRIPTION_ID");

            if (subId == invalidSubId)
            {
                Logger.Log("The Subscription ID is invalid: " + subId);
                return(null);
            }
            object[] idParam = new object[1] {
                subId
            };
            telManager = PlatformIntegrationUtil.Call <AndroidJavaObject>(telManager, "createForSubscriptionId", idParam);

            return(telManager);
        }