Android Question [Solved] Native Ads Advanced with MediaView

Discussion in 'Android Questions' started by asales, Sep 5, 2018.

  1. asales

    asales Well-Known Member Licensed User

  2. Erel

    Erel Administrator Staff Member Licensed User

    This code creates a MediaView, adds it to the content panel and calls setMediaView:
    Code:
    Dim MediaView As JavaObject
    MediaView.InitializeNewInstance(
    "com/google/android/gms/ads/formats/MediaView".Replace("/""."), Array(ctxt))
    content.AddView(MediaView, 
    00100dip100dip)
    NativeContentAdView.RunMethod(
    "setMediaView"Array(MediaView))
     
    asales likes this.
  3. asales

    asales Well-Known Member Licensed User

    The id of the Ad unit to test the native advanced with mediaview is:
    ca-app-pub-3940256099942544/1044960115
    (https://developers.google.com/admob/android/test-ads)

    I changed the code to test if ad has a video:
    Code:
    Dim vid As JavaObject = NativeUnifiedAd.RunMethod("getVideoController"Null)
    Dim hasvid As Boolean = vid.RunMethod("hasVideoContent"Null)
    If vid.IsInitialized Then
       
    Dim MediaView As JavaObject
       MediaView.InitializeNewInstance(
    "com/google/android/gms/ads/formats/MediaView".Replace("/""."), Array(ctxt))
       content.AddView(MediaView, 
    10dip40dip200dip200dip)
       NativeUnifiedAdView.RunMethod(
    "setMediaView"Array(MediaView))
    End If
     
    arastoo and eps like this.
  4. asales

    asales Well-Known Member Licensed User

    Updated code:

    Checks if there is a video, if don't check for images.

    Code:
    Dim vid As JavaObject = NativeUnifiedAd.RunMethod("getVideoController"Null)
    Dim hasvid As Boolean = vid.RunMethod("hasVideoContent"Null)
    If hasvid = True Then
        
    If vid.IsInitialized Then
           
    Dim MediaView As JavaObject
           MediaView.InitializeNewInstance(
    "com/google/android/gms/ads/formats/MediaView".Replace("/""."), Array(ctxt))
           content.AddView(MediaView, 
    10dip40dip200dip200dip)
           NativeUnifiedAdView.RunMethod(
    "setMediaView"Array(MediaView))
        
    End If
    Else
        
    Dim images As List = NativeUnifiedAd.RunMethod("getImages"Null)
        
    If images.IsInitialized And images.Size > 0 Then
            
    Dim imgView As Panel = pAdmob.GetView(5)  'example
            Dim image As JavaObject = images.Get(0)
            imgView.Background = 
    image.RunMethod("getDrawable"Null)
            NativeUnifiedAdView.RunMethod(
    "setImageView"Array(imgView))
        
    End If
    End If
     
    arastoo likes this.
  5. asales

    asales Well-Known Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice