public override int Create(string placementId,
                                   NativeAd nativeAd)
        {
            AdUtility.prepare();
            AndroidJavaClass  unityPlayer     = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
            AndroidJavaObject context         = currentActivity.Call <AndroidJavaObject>("getApplicationContext");

            AndroidJavaObject bridgedNativeAd = new AndroidJavaObject("com.facebook.ads.NativeAd", context, placementId);

            NativeAdBridgeListenerProxy proxy = new NativeAdBridgeListenerProxy(nativeAd, bridgedNativeAd);

            bridgedNativeAd.Call("setAdListener", proxy);

            NativeAdBridgeImpressionListenerProxy impressionListenerProxy = new NativeAdBridgeImpressionListenerProxy(nativeAd, bridgedNativeAd);

            bridgedNativeAd.Call("setImpressionListener", impressionListenerProxy);

            NativeAdContainer nativeAdContainer = new NativeAdContainer(nativeAd);

            nativeAdContainer.bridgedNativeAd         = bridgedNativeAd;
            nativeAdContainer.listenerProxy           = proxy;
            nativeAdContainer.impressionListenerProxy = impressionListenerProxy;

            int key = NativeAdBridgeAndroid.lastKey;

            NativeAdBridgeAndroid.nativeAds.Add(key, nativeAdContainer);
            NativeAdBridgeAndroid.lastKey++;
            return(key);
        }
Exemplo n.º 2
0
        public override int Create(string placementId, NativeAd nativeAd)
        {
            AdUtility.prepare();
            AndroidJavaClass            androidJavaClass            = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject           @static                     = androidJavaClass.GetStatic <AndroidJavaObject>("currentActivity");
            AndroidJavaObject           androidJavaObject           = @static.Call <AndroidJavaObject>("getApplicationContext", new object[0]);
            AndroidJavaObject           androidJavaObject2          = new AndroidJavaObject("com.facebook.ads.NativeAd", androidJavaObject, placementId);
            NativeAdBridgeListenerProxy nativeAdBridgeListenerProxy = new NativeAdBridgeListenerProxy(nativeAd, androidJavaObject2);

            androidJavaObject2.Call("setAdListener", nativeAdBridgeListenerProxy);
            NativeAdContainer nativeAdContainer = new NativeAdContainer(nativeAd);

            nativeAdContainer.bridgedNativeAd = androidJavaObject2;
            nativeAdContainer.listenerProxy   = nativeAdBridgeListenerProxy;
            int num = lastKey;

            nativeAds.Add(num, nativeAdContainer);
            lastKey++;
            return(num);
        }
        public override int Create(string placementId, NativeAd nativeAd)
        {
            AdUtility.prepare();
            AndroidJavaClass  class2 = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject obj3   = class2.GetStatic <AndroidJavaObject>("currentActivity").Call <AndroidJavaObject>("getApplicationContext", new object[0]);

            object[]                    args            = new object[] { obj3, placementId };
            AndroidJavaObject           bridgedNativeAd = new AndroidJavaObject("com.facebook.ads.NativeAd", args);
            NativeAdBridgeListenerProxy proxy           = new NativeAdBridgeListenerProxy(nativeAd, bridgedNativeAd);

            object[] objArray2 = new object[] { proxy };
            bridgedNativeAd.Call("setAdListener", objArray2);
            NativeAdContainer container = new NativeAdContainer(nativeAd)
            {
                bridgedNativeAd = bridgedNativeAd,
                listenerProxy   = proxy
            };
            int lastKey = NativeAdBridgeAndroid.lastKey;

            nativeAds.Add(lastKey, container);
            NativeAdBridgeAndroid.lastKey++;
            return(lastKey);
        }
Exemplo n.º 4
0
        override public int Create(string placementId, NativeAdBase nativeAd)
        {
            AdUtility.Prepare();
            AndroidJavaClass  unityPlayer     = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
            AndroidJavaObject context         = currentActivity.Call <AndroidJavaObject>("getApplicationContext");

            String androidAdClass = "";

            if (nativeAd.nativeAdType == NativeAdType.NativeAd)
            {
                androidAdClass = "com.facebook.ads.NativeAd";
            }
            else if (nativeAd.nativeAdType == NativeAdType.NativeBannerAd)
            {
                androidAdClass = "com.facebook.ads.NativeBannerAd";
            }

            AndroidJavaObject bridgedNativeAd = new AndroidJavaObject(androidAdClass, context, placementId);

            NativeAdBridgeListenerProxy proxy = new NativeAdBridgeListenerProxy(nativeAd, bridgedNativeAd);

            bridgedNativeAd.Call("setAdListener", proxy);

            NativeAdContainer nativeAdContainer = new NativeAdContainer(nativeAd)
            {
                bridgedNativeAd = bridgedNativeAd,
                listenerProxy   = proxy,
                context         = context
            };

            int key = NativeAdBridgeAndroid.lastKey;

            NativeAdBridgeAndroid.nativeAds.Add(key, nativeAdContainer);
            NativeAdBridgeAndroid.lastKey++;
            return(key);
        }
Exemplo n.º 5
0
        public override int Create (string placementId,
                                    NativeAd nativeAd)
        {
            AdUtility.prepare ();
            AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
            AndroidJavaObject context = currentActivity.Call<AndroidJavaObject>("getApplicationContext");

            AndroidJavaObject bridgedNativeAd = new AndroidJavaObject("com.facebook.ads.NativeAd", context, placementId);

            NativeAdBridgeListenerProxy proxy = new NativeAdBridgeListenerProxy (nativeAd, bridgedNativeAd);
            bridgedNativeAd.Call ("setAdListener", proxy);

            NativeAdContainer nativeAdContainer = new NativeAdContainer (nativeAd);
            nativeAdContainer.bridgedNativeAd = bridgedNativeAd;
            nativeAdContainer.listenerProxy = proxy;

            int key = NativeAdBridgeAndroid.lastKey;
            NativeAdBridgeAndroid.nativeAds.Add(key, nativeAdContainer);
            NativeAdBridgeAndroid.lastKey++;
            return key;
        }