コード例 #1
0
 private void OnDestroy()
 {
     if (t != null)
     {
         t.Abort();
     }
     peer.Close();
     multicastLock?.Call("release");
 }
コード例 #2
0
 // Toggles high detail logging on/off
 public static void EnableLogging(bool enable)
 {
     plugin?.Call("enableLogging", enable);
     if (enable)
     {
         Debug.LogWarning("YOU HAVE ENABLED HIGH DETAIL LOGS. DO NOT DISTRIBUTE THE GENERATED APK PUBLICLY. IT WILL DUMP SENSITIVE INFORMATION TO THE CONSOLE!");
     }
 }
コード例 #3
0
        /// <summary>
        /// Clean up at end
        /// </summary>
        private void OnDestroy()
        {
            foreach (UdpClient client in clients)
            {
                client.Close();
            }

            multicastLock?.Call("release");
        }
コード例 #4
0
        /// <summary>
        /// Clean up at end
        /// </summary>
        private void OnDisable()
        {
            foreach (UdpClient client in clients)
            {
                client.Close();
            }

            multicastLock?.Call("release");
            keepThreads = false;
        }
コード例 #5
0
        void EndpMulticastLock()
        {
#if UNITY_ANDROID
            if (!hasMulticastLock)
            {
                return;
            }

            multicastLock?.Call("release");
            hasMulticastLock = false;
#endif
        }
コード例 #6
0
ファイル: Init.cs プロジェクト: shardengine/MobileUO
    private static string GetAndroidExternalFilesDir()
    {
        #if UNITY_ANDROID && !UNITY_EDITOR
        try
        {
            using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
            {
                using (AndroidJavaObject context = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity"))
                {
                    // Get all available external file directories (emulated and sdCards)
                    AndroidJavaObject[] externalFilesDirectories =
                        context.Call <AndroidJavaObject[], string>("getExternalFilesDirs", null);
                    AndroidJavaObject emulated = null;
                    AndroidJavaObject sdCard   = null;

                    for (int i = 0; i < externalFilesDirectories.Length; i++)
                    {
                        AndroidJavaObject directory = externalFilesDirectories[i];
                        using (AndroidJavaClass environment = new AndroidJavaClass("android.os.Environment"))
                        {
                            // Check which one is the emulated and which the sdCard.
                            bool isRemovable = environment.CallStatic <bool>("isExternalStorageRemovable", directory);
                            bool isEmulated  = environment.CallStatic <bool>("isExternalStorageEmulated", directory);
                            if (isEmulated)
                            {
                                emulated = directory;
                            }
                            else if (isRemovable)
                            {
                                sdCard = directory;
                            }
                        }
                    }

                    // Return the sdCard if available
                    return(sdCard?.Call <string>("getAbsolutePath"));
                }
            }
        }
        catch (Exception e)
        {
            Debug.LogException(e);
            return(null);
        }
        #endif
        return(null);
    }
コード例 #7
0
        /// <summary>
        /// Returns the coordinates of the Hinge in a Rect object.
        /// </summary>
        public static RectInt GetHinge()
        {
            var hinge = OnPlayer.Run(p =>
            {
                return(screenInfoObject?.Call <AndroidJavaObject>("getHinge"));
            });

            if (hinge != null)
            {
                var left   = hinge.Get <int>("left");
                var top    = hinge.Get <int>("top");
                var width  = hinge.Call <int>("width");
                var height = hinge.Call <int>("height");

                return(new RectInt(left, top, width, height));
            }
            else
            {
                return(new RectInt(0, 0, 0, 0)); // TODO: cannot return null - is ok?
            }
        }
コード例 #8
0
ファイル: NFC.cs プロジェクト: GemToken/Experiments
    void Update()
    {
        if (Application.platform == RuntimePlatform.Android)
        {
            if (!nfcEnabled(context) && nfcIsOn)
            {
                tagOutputText.text  = "Warning: NFC is off!";
                tagOutputText.color = Color.red;
                nfcIsOn             = false;
            }
            else if (nfcEnabled(context) && !nfcIsOn)
            {
                tagOutputText.text  = "Tap an NFC figure to start playing.";
                tagOutputText.color = Color.white;
                nfcIsOn             = true;
            }

            try
            {
                // Create new NFC Android object
                mActivity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic <AndroidJavaObject>("currentActivity"); // Activities open apps
                mIntent   = mActivity.Call <AndroidJavaObject>("getIntent");
                sAction   = mIntent.Call <String>("getAction");

                if (sAction == "android.nfc.action.NDEF_DISCOVERED")
                {
                    sAction = null;
                    Debug.Log("Tag of type NDEF");
                    AndroidJavaObject[] mNdefMessage = mIntent.Call <AndroidJavaObject[]>("getParcelableArrayExtra", "android.nfc.extra.NDEF_MESSAGES");
                    if (mNdefMessage != null)
                    {
                        // Handle NFC payload
                        AndroidJavaObject[] mNdefRecord = mNdefMessage[0].Call <AndroidJavaObject[]>("getRecords");
                        byte[] payLoad         = mNdefRecord[0].Call <byte[]>("getPayload");
                        byte[] adjustedPayload = new byte[payLoad.Length - 3];

                        // Necessary adjustment to remove the language bytes from text. May need changing in the future.
                        Array.Copy(payLoad, 3, adjustedPayload, 0, adjustedPayload.Length);
                        payloadText = System.Text.Encoding.UTF8.GetString(adjustedPayload);
                        //tagOutputText.text = "You Scanned: " + text;
                        tagID = payloadText;
                        mIntent.Call("removeExtra", "android.nfc.extra.TAG");

                        loadFigure(payloadText);

                        mNdefMessage = null;
                    }
                    else
                    {
                        if (!tagFound)
                        {
                            tagOutputText.text = "No data on tag.";
                        }
                    }
                    tagFound = true;

                    // Two lines below allow for multiple tag scanning
                    mIntent.Call("removeExtra", "android.nfc.extra.TAG");
                    mIntent.Call("removeExtra", "android.nfc.extra.NDEF_MESSAGES");
                    return;
                }
                else if (sAction == "android.nfc.action.TECH_DISCOVERED")
                {
                    //duplicate code above if this field becomes necessary
                    return;
                }
                else if (sAction == "android.nfc.action.TAG_DISCOVERED")
                {
                    sAction = null;
                    Debug.Log("This type of tag is not supported !");
                }
                else
                {
                    sAction = null;
                    //tag_output_text.text = "...Awaiting Scan...";
                    return;
                }
                sAction = null;
            }
            catch (Exception ex)
            {
                string text = ex.Message;
                print(ex.Message);
                tagOutputText.text = "Error occured during NFC Scan";
            }
        }
    }
コード例 #9
0
 public static void SetupAndroidTheme(int primaryARGB, int darkARGB, string label = null)
 {
     #if UNITY_ANDROID && !UNITY_EDITOR
     label             = label ?? Application.productName;
     Screen.fullScreen = false;
     AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic <AndroidJavaObject>("currentActivity");
     activity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
     {
         AndroidJavaClass layoutParamsClass = new AndroidJavaClass("android.view.WindowManager$LayoutParams");
         int flagFullscreen                = layoutParamsClass.GetStatic <int>("FLAG_FULLSCREEN");
         int flagNotFullscreen             = layoutParamsClass.GetStatic <int>("FLAG_FORCE_NOT_FULLSCREEN");
         int flagDrawsSystemBarBackgrounds = layoutParamsClass.GetStatic <int>("FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
         AndroidJavaObject windowObject    = activity.Call <AndroidJavaObject>("getWindow");
         windowObject.Call("clearFlags", flagFullscreen);
         windowObject.Call("addFlags", flagNotFullscreen);
         windowObject.Call("addFlags", flagDrawsSystemBarBackgrounds);
         int sdkInt   = new AndroidJavaClass("android.os.Build$VERSION").GetStatic <int>("SDK_INT");
         int lollipop = 21;
         if (sdkInt > lollipop)
         {
             windowObject.Call("setStatusBarColor", darkARGB);
             string myName = activity.Call <string>("getPackageName");
             AndroidJavaObject packageManager  = activity.Call <AndroidJavaObject>("getPackageManager");
             AndroidJavaObject drawable        = packageManager.Call <AndroidJavaObject>("getApplicationIcon", myName);
             AndroidJavaObject taskDescription = new AndroidJavaObject("android.app.ActivityManager$TaskDescription", label, drawable.Call <AndroidJavaObject>("getBitmap"), primaryARGB);
             activity.Call("setTaskDescription", taskDescription);
         }
     }));
     #endif
 }
コード例 #10
0
 public bool IsReady()
 {
     return(androidWindowAd.Call <bool>("isLoaded"));
 }
コード例 #11
0
 public static void ShowText(string msg, string body)
 {
     unityActivity.Call("ShareText", msg, body);
 }
コード例 #12
0
    public void SetConfigForPhoneSys()
    {
        // all config read finish then call this function.
#if ANDROID_SDK
        if (Application.platform == RuntimePlatform.Android)
        {
            AndroidJavaClass  jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject jo = jc.GetStatic <AndroidJavaObject>("currentActivity");

            object[] datas = new object[] { (int)GameSystem.Instance.CommonConfig.GetUInt("gHpRestoreTime") };
            jo.Call("setHpRestoreTime", datas);
        }
#endif

#if IOS_SDK
        setHpRestoreTime((int)GameSystem.Instance.CommonConfig.GetUInt("gHpRestoreTime"));
#endif
        foreach (PushItem item in _items.Values)
        {
            switch (item.type)
            {
            // first win push info modify
            case 5:
            {
                PushItem pi = null;
                if (_pushInfos.TryGetValue(item.type, out pi))
                {
                    item.date = pi.date;
                    item.time = pi.time;
                    //将信息存储到pushInfo里面,获得首胜后再次推送
                    pi = item;

//						_pushInfos.Remove(pi.type);
                                                #if ANDROID_SDK
                    if (Application.platform == RuntimePlatform.Android)
                    {
                        AndroidJavaClass  jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
                        AndroidJavaObject jo = jc.GetStatic <AndroidJavaObject>("currentActivity");
                        int id     = (int)item.id;
                        int type   = (int)item.type;
                        int online = (int)item.online;

                        /*
                         *      public void SetLocalPush(int id, int online, int second, String content )
                         */
                        int time;
                        if (!int.TryParse(item.time, out time))
                        {
                            time = 0;
                        }
                        object[] datas = new object[] { id, online, time, item.content };
//							Debug.Log("SetLocalPush push config "+time+","+type+","+item.content);
                        jo.Call("SetLocalPush", datas);
                    }
                                                #endif
                                                #if IOS_SDK
//						int id = (int)item.id;
//						int type = (int)item.type;
//						int online = (int)item.online;
//						Debug.Log("PushConfig recvPush Start called");
//						recvPush(id, type, item.date,item.time,online,item.content );
//						Debug.Log("PushConfig SetLocalPush End called");
                                                #endif
                }

                break;
            }

            default:
            {
                                        #if ANDROID_SDK
                if (Application.platform == RuntimePlatform.Android)
                {
                    AndroidJavaClass  jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
                    AndroidJavaObject jo = jc.GetStatic <AndroidJavaObject>("currentActivity");
                    int id     = (int)item.id;
                    int type   = (int)item.type;
                    int online = (int)item.online;

//					Debug.Log("recvPush push config "+item.time+","+item.type+","+item.content);
                    object[] datas = new object[] { id, type, item.date, item.time, online, item.content };
                    jo.Call("RecvPush", datas);

                    if (type == 4)
                    {
                        _hpStr = item.content;
                        _hpId  = (int)item.id;
                    }
                }
                                        #endif
                                        #if IOS_SDK
                int id     = (int)item.id;
                int type   = (int)item.type;
                int online = (int)item.online;
                Debug.Log("PushConfig recvPush Start called");
                recvPush(id, type, item.date, item.time, online, item.content);
                Debug.Log("PushConfig recvPush End called");
                if (type == 4)
                {
                    _hpStr = item.content;
                    _hpId  = (int)item.id;
                }
                                        #endif
                break;
            }
            }
        }
    }
コード例 #13
0
 public bool HasBluetoothAdapter()
 {
     return(bluetoothHelper != null && bluetoothHelper.Call <bool>("hasBluetoothAdapter"));
 }
コード例 #14
0
 public int GetCameraPlaneID()
 {
     return(CameraControls.Call <int>("getCameraPlaneID"));
 }
コード例 #15
0
    public void StartAppByPackage(string pkname)
    {
#if UNITY_ANDROID && !UNITY_EDITOR
        mLauncherApp.Call("StartAppByPackage", pkname);
#endif
    }
コード例 #16
0
        public static TurnBasedMatch ConvertMatch(string playerId, AndroidJavaObject matchObj)
        {
            List <AndroidJavaObject> toDispose = new List <AndroidJavaObject>();

            Logger.d("AndroidTbmpClient.ConvertMatch, playerId=" + playerId);

            string matchId;

            byte[]             data;
            bool               canRematch;
            int                availableAutomatchSlots;
            string             selfParticipantId;
            List <Participant> participants = new List <Participant>();
            string             pendingParticipantId;

            TurnBasedMatch.MatchTurnStatus turnStatus;
            TurnBasedMatch.MatchStatus     matchStatus;
            int variant;

            matchId = matchObj.Call <string>("getMatchId");
            AndroidJavaObject dataObj = JavaUtil.CallNullSafeObjectMethod(matchObj, "getData");

            toDispose.Add(dataObj);
            data       = JavaUtil.ConvertByteArray(dataObj);
            canRematch = matchObj.Call <bool>("canRematch");
            availableAutomatchSlots = matchObj.Call <int>("getAvailableAutoMatchSlots");
            selfParticipantId       = matchObj.Call <string>("getParticipantId", playerId);

            AndroidJavaObject participantIds = matchObj.Call <AndroidJavaObject>("getParticipantIds");

            toDispose.Add(participantIds);
            int participantCount = participantIds.Call <int>("size");

            for (int i = 0; i < participantCount; i++)
            {
                string            thisId   = participantIds.Call <string>("get", i);
                AndroidJavaObject thisPart = matchObj.Call <AndroidJavaObject>("getParticipant", thisId);
                toDispose.Add(thisPart);
                Participant p = JavaUtil.ConvertParticipant(thisPart);
                participants.Add(p);
            }

            pendingParticipantId = matchObj.Call <string>("getPendingParticipantId");
            turnStatus           = JavaUtil.ConvertTurnStatus(matchObj.Call <int>("getTurnStatus"));
            matchStatus          = JavaUtil.ConvertMatchStatus(matchObj.Call <int>("getStatus"));
            variant = matchObj.Call <int>("getVariant");

            // cleanup
            foreach (AndroidJavaObject obj in toDispose)
            {
                if (obj != null)
                {
                    obj.Dispose();
                }
            }

            // participants should be sorted by participant ID
            participants.Sort();

            return(new TurnBasedMatch(matchId, data, canRematch, selfParticipantId,
                                      participants, availableAutomatchSlots,
                                      pendingParticipantId, turnStatus, matchStatus, variant));
        }
コード例 #17
0
        private string getTimeString(DateTime dateTime)
        {
            long dateTimeTicksUTC = TimeZoneInfo.ConvertTimeToUtc(dateTime).Ticks;

            DateTime dtFrom        = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
            long     currentMillis = (dateTimeTicksUTC - dtFrom.Ticks) / 10000;

            AndroidJavaObject date = new AndroidJavaObject("java.util.Date", currentMillis);

            return(instance.Call <string>("getTimeString", date));
        }
コード例 #18
0
ファイル: QuickSDKImp.cs プロジェクト: daxingyou/AraleEngine
        public void setListener(QuickSDKListener listener)
        {
            Debug.Log("gameObject is " + listener.gameObject.name);
            if (listener == null)
            {
                Debug.LogError("set QuickSDKListener error, listener is null");
                return;
            }
            string gameObjectName = listener.gameObject.name;

            if (ao == null)
            {
                Debug.LogError("setListener error, current activity is null");
            }
            else
            {
                ao.Call("setUnityGameObjectName", gameObjectName);
            }
        }
コード例 #19
0
    public static KTUser CurrentAccount()
    {
        //string str = (string)KT_CurrentAccount();

        //Hashtable data = (Hashtable)KTJSON.jsonDecode(str);

        //return new KTUser(data);
#if UNITY_ANDROID
        AndroidJavaObject joUser = null;
        try
        {
            joUser = KTPlayAndroid.joKTPlayAdapter.CallStatic <AndroidJavaObject>("currentAccount");
        }
        catch (System.Exception e)
        {
            Debug.Log("Failed to CurrentAccount: " + e.Message);
            return(null);
        }

        if (joUser == null)
        {
            return(null);
        }

        string userid              = joUser.Call <string>("getUserId");
        string headerurl           = joUser.Call <string>("getHeaderUrl");
        string nickname            = joUser.Call <string>("getNickname");
        int    gender              = joUser.Call <int>("getGender");
        string city                = joUser.Call <string>("getCity");
        string score               = joUser.Call <string>("getScore");
        long   rank                = joUser.Call <long>("getRank");
        string snsuserid           = joUser.Call <string>("getSnsUserId");
        string logintype           = joUser.Call <string>("getLoginType");
        string gameUserId          = joUser.Call <string>("getGameUserId");
        bool   needPresentNickname = joUser.Call <bool>("getNeedPresentNickname");

        KTUser user = new KTUser();
        user.setUserId(userid);
        user.setHeaderUrl(headerurl);
        user.setNickname(nickname);
        user.setGender(gender);
        user.setCity(city);
        user.setScore(score);
        user.setRank(rank);
        user.setSnsUserId(snsuserid);
        user.setLoginType(logintype);
        user.setGameUserId(gameUserId);
        user.setNeedPresentNickname(needPresentNickname);

        return(user);
#else
        return(null);
#endif
    }
コード例 #20
0
        /// Check to see if any chartboost ad or view is visible

        public static bool isAnyViewVisible()
        {
            bool handled = false;

            if (!checkInitialized())
            {
                return(handled);
            }

            handled = _plugin.Call <bool>("isAnyViewVisible");

            Log("Android : isAnyViewVisible = " + handled);

            return(handled);
        }
コード例 #21
0
 public override void Show()
 {
     javaObject.Call("show");
 }
コード例 #22
0
    /// <summary>
    /// 设置推送消息
    /// </summary>
    /// <param name="id">Identifier.</param>
    /// <param name="type">Type.</param>
    /// <param name="online">Online.</param>
    /// <param name="date">Date.</param>
    /// <param name="time">Time.</param>
    /// <param name="content">Content.</param>
    public void SetPushInfo(int id           /*推送ID*/
                            , int type       /*推送类型*/
                            , int online     /*离线提示或者游戏内提示*/
                            , int date       /*推送日期*/
                            , int time       /*推送时间(剩余时间/s)*/
                            , string content /*推送文本*/
                            )
    {
        string s_date = "" + date;
//		System.DateTime dt = System.DateTime.Now;
//		dt = dt.AddSeconds(time);
        string s_time = "" + time;      //dt.GetDateTimeFormats('t')[0].ToString()";
//		Debug.Log("s_timet "+s_time);
        PushItem pi;
        //modify exist element
        bool configAlreadyRead = false;

        foreach (PushItem item in _items.Values)
        {
            //已经读取了配置从配置设置数据直接发送
            if (item.type == type)
            {
                configAlreadyRead = true;
                content           = item.content;
                online            = (int)item.online;
                id = (int)item.id;
                break;
            }
        }
        if (!configAlreadyRead)
        {
            //如果已经发送过一次,通过配置来重置时间再次发送
            if (_pushInfos.ContainsKey((uint)type))
            {
                pi      = _pushInfos[(uint)type];
                pi.time = s_time;
                content = pi.content;
                online  = (int)pi.online;
                id      = (int)pi.id;
            }
            else
            {
                //还未读取配置,设置配置时间
                pi         = new PushItem();
                pi.id      = (uint)id;
                pi.date    = s_date;
                pi.online  = (uint)online;
                pi.time    = s_time;
                pi.content = content;
                pi.type    = (uint)type;
                _pushInfos.Add(pi.type, pi);
                Debug.Log("send push info after config read.");
                return;
            }
        }
        Debug.Log("send push info directly.");

        #if ANDROID_SDK
        if (Application.platform == RuntimePlatform.Android)
        {
            AndroidJavaClass  jc    = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject jo    = jc.GetStatic <AndroidJavaObject>("currentActivity");
            object[]          datas = new object[] { id, online, time, content };
//			Debug.Log("SetLocalPush push config "+time+","+type+","+content);
            jo.Call("SetLocalPush", datas);
        }
        #endif
        #if IOS_SDK
//		Debug.Log("PushConfig recvPush Start called");
//		recvPush(id, type, s_date,time,online,content );
//		Debug.Log("PushConfig recvPush End called");
//		if( type == 4)
//		{
//			_hpStr = content;
//			_hpId = id;
//		}
        #endif
    }
コード例 #23
0
 public bool isInterstitialReady()
 {
     return mChartboostObject.Call<bool>("IsInterstitialReady");
 }
コード例 #24
0
 public static void SetBool(AndroidJavaObject properties, string key, bool val)
 {
     properties.Call <AndroidJavaObject>("set", key, val);
 }
コード例 #25
0
 public override void RegisterForPushNotifications()
 {
     pushwoosh.Call("registerForPushNotifications");
 }
コード例 #26
0
 public static void SetDate(AndroidJavaObject properties, string key, DateTime val)
 {
     properties.Call <AndroidJavaObject>("set", key, JavaDateHelper.DateTimeConvert(val));
 }
コード例 #27
0
 public static string AsString(this AndroidJavaObject javaString) => javaString?.Call <string>("toString");
コード例 #28
0
 public static void Clear(AndroidJavaObject properties, string key)
 {
     properties.Call <AndroidJavaObject>("clear", key);
 }
コード例 #29
0
 public static void SetNumber(AndroidJavaObject properties, string key, double val)
 {
     properties.Call <AndroidJavaObject>("set", key, JavaNumberHelper.Convert(val));
 }
コード例 #30
0
ファイル: Utils.cs プロジェクト: artemy0/Quiz
        public static AndroidJavaObject GetAdRequestJavaObject(AdRequest request)
        {
            AndroidJavaObject adRequestBuilder = new AndroidJavaObject(AdRequestBuilderClassName);

            foreach (string keyword in request.Keywords)
            {
                adRequestBuilder.Call <AndroidJavaObject>("addKeyword", keyword);
            }

            foreach (string deviceId in request.TestDevices)
            {
                if (deviceId == AdRequest.TestDeviceSimulator)
                {
                    string emulatorDeviceId = new AndroidJavaClass(AdRequestClassName)
                                              .GetStatic <string>("DEVICE_ID_EMULATOR");
                    adRequestBuilder.Call <AndroidJavaObject>("addTestDevice", emulatorDeviceId);
                }
                else
                {
                    adRequestBuilder.Call <AndroidJavaObject>("addTestDevice", deviceId);
                }
            }

            if (request.Birthday.HasValue)
            {
                DateTime          birthday       = request.Birthday.GetValueOrDefault();
                AndroidJavaObject birthdayObject = new AndroidJavaObject(
                    DateClassName, birthday.Year, birthday.Month, birthday.Day);
                adRequestBuilder.Call <AndroidJavaObject>("setBirthday", birthdayObject);
            }

            if (request.Gender.HasValue)
            {
                int?genderCode = null;
                switch (request.Gender.GetValueOrDefault())
                {
                case Api.Gender.Unknown:
                    genderCode = new AndroidJavaClass(AdRequestClassName)
                                 .GetStatic <int>("GENDER_UNKNOWN");
                    break;

                case Api.Gender.Male:
                    genderCode = new AndroidJavaClass(AdRequestClassName)
                                 .GetStatic <int>("GENDER_MALE");
                    break;

                case Api.Gender.Female:
                    genderCode = new AndroidJavaClass(AdRequestClassName)
                                 .GetStatic <int>("GENDER_FEMALE");
                    break;
                }

                if (genderCode.HasValue)
                {
                    adRequestBuilder.Call <AndroidJavaObject>("setGender", genderCode);
                }
            }

            if (request.TagForChildDirectedTreatment.HasValue)
            {
                adRequestBuilder.Call <AndroidJavaObject>(
                    "tagForChildDirectedTreatment",
                    request.TagForChildDirectedTreatment.GetValueOrDefault());
            }

            // Denote that the request is coming from this Unity plugin.
            adRequestBuilder.Call <AndroidJavaObject>(
                "setRequestAgent",
                "unity-" + AdRequest.Version);
            AndroidJavaObject bundle = new AndroidJavaObject(BundleClassName);

            foreach (KeyValuePair <string, string> entry in request.Extras)
            {
                bundle.Call("putString", entry.Key, entry.Value);
            }

            bundle.Call("putString", "is_unity", "1");

            AndroidJavaObject extras = new AndroidJavaObject(AdMobExtrasClassName, bundle);

            adRequestBuilder.Call <AndroidJavaObject>("addNetworkExtras", extras);

            foreach (MediationExtras mediationExtra in request.MediationExtras)
            {
                AndroidJavaObject mediationExtrasBundleBuilder =
                    new AndroidJavaObject(mediationExtra.AndroidMediationExtraBuilderClassName);
                AndroidJavaObject map = new AndroidJavaObject("java.util.HashMap");

                foreach (KeyValuePair <string, string> entry in mediationExtra.Extras)
                {
                    map.Call <AndroidJavaObject>("put", entry.Key, entry.Value);
                }

                AndroidJavaObject mediationExtras =
                    mediationExtrasBundleBuilder.Call <AndroidJavaObject>("buildExtras", map);

                if (mediationExtras != null)
                {
                    adRequestBuilder.Call <AndroidJavaObject>(
                        "addNetworkExtrasBundle",
                        mediationExtrasBundleBuilder.Call <AndroidJavaClass>("getAdapterClass"),
                        mediationExtras);

                    adRequestBuilder.Call <AndroidJavaObject>(
                        "addCustomEventExtrasBundle",
                        mediationExtrasBundleBuilder.Call <AndroidJavaClass>("getAdapterClass"),
                        mediationExtras);
                }
            }

            return(adRequestBuilder.Call <AndroidJavaObject>("build"));
        }