Class InMobiNative


  • public final class InMobiNative
    extends java.lang.Object
    Use this class to integrate native ads.

    Note This class is not thread-safe. All methods on instances of this class must be called on the UI thread.

    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void destroy()
      Destroy the Native ad view.
      java.lang.String getAdCtaText()  
      java.lang.String getAdDescription()  
      java.lang.String getAdIconUrl()  
      java.lang.String getAdLandingPageUrl()  
      org.json.JSONObject getAdMetaInfo()
      Deprecated.
      float getAdRating()  
      java.lang.String getAdTitle()  
      java.lang.String getCreativeId()
      Deprecated.
      org.json.JSONObject getCustomAdContent()  
      android.view.View getPrimaryViewOfWidth​(android.content.Context context, android.view.View convertView, android.view.ViewGroup parent, int viewWidthInPixels)
      Method to return a native ad view.
      android.view.View getPrimaryViewOfWidth​(android.view.View convertView, android.view.ViewGroup parent, int viewWidthInPixels)
      Deprecated.
      void getSignals()
      Called to create the request payload & the value is returned in AdEventListener.onRequestPayloadCreated(byte[]) callback on success, and in case of failure AdEventListener.onRequestPayloadCreationFailed(InMobiAdRequestStatus) is invoked.
      boolean isAppDownload()  
      boolean isReady()
      Returns true if the native was loaded successfully and is ready to be shown.
      java.lang.Boolean isVideo()
      This api provides information if the ad returned contains a video or not.
      void load()
      Submit a request to load Native ad.
      void load​(byte[] response)
      Called to render the ad with the provided response.
      void load​(android.content.Context context)
      Submit a request to load ad content.
      void pause()
      Pauses any extra processing associated with this InMobiNative ad.
      void reportAdClickAndOpenLandingPage()  
      void resume()
      Resumes an InMobiNative ad after a previous call to pause().
      void setContentUrl​(java.lang.String contentUrl)
      Set the current context of the app.
      void setExtras​(java.util.Map<java.lang.String,​java.lang.String> extras)
      Set any additional custom parameters that will be sent in the ad request.
      void setKeywords​(java.lang.String keywords)
      Set comma delimited keywords for targeting purpose
      void setListener​(NativeAdEventListener listener)
      Method to update the pub listener
      void setVideoEventListener​(VideoEventListener listener)
      Method to add or update the video events listener for pub
      void showOnLockScreen​(InMobiNative.LockScreenListener lockScreenListener)
      Call this method to inform SDK that this Ad will be shown on LockScreen.
      void takeAction()
      Call this method to take action which is caused by any user interaction with ad view on Lockscreen.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • InMobiNative

        public InMobiNative​(android.content.Context context,
                            long placementId,
                            NativeAdEventListener listener)
                     throws SdkNotInitializedException
        Creates an instance of InMobiNative.
        Parameters:
        context - Provide the current context instance
        placementId - The placementId for which the object is created
        listener - Listener to get lifecycle callbacks
        Throws:
        SdkNotInitializedException - If the IM-SDK was not initialized before creating ad object
    • Method Detail

      • setListener

        public void setListener​(NativeAdEventListener listener)
        Method to update the pub listener
        Parameters:
        listener - Represents the new listener
      • setVideoEventListener

        public void setVideoEventListener​(VideoEventListener listener)
        Method to add or update the video events listener for pub
        Parameters:
        listener - Represents the new listener
      • getSignals

        public void getSignals()
        Called to create the request payload & the value is returned in AdEventListener.onRequestPayloadCreated(byte[]) callback on success, and in case of failure AdEventListener.onRequestPayloadCreationFailed(InMobiAdRequestStatus) is invoked.
      • load

        public void load​(byte[] response)
        Called to render the ad with the provided response. Once the SDK starts loading the provided response, it will start giving callbacks through NativeAdEventListener listener.
        Parameters:
        response - Represents the response to be used to render an ad
      • load

        public void load()
        Submit a request to load Native ad. This method returns immediately upon enqueuing a request. Client code will be notified of the result on the NativeAdEventListener callback that it supplied while instantiating an InMobiNative object.

        Note This method must be called on the UI thread. Failure to do so will affect your ability to monetize with the InMobi Ad SDK.

      • load

        public void load​(android.content.Context context)
        Submit a request to load ad content. Use this method in order to change the context where the ad needs to originally load.
        Parameters:
        context - the Context where the ad will be rendered.
      • showOnLockScreen

        public void showOnLockScreen​(InMobiNative.LockScreenListener lockScreenListener)
        Call this method to inform SDK that this Ad will be shown on LockScreen. This method should be called before load(Context) or load().
        Parameters:
        lockScreenListener -
      • takeAction

        public void takeAction()
        Call this method to take action which is caused by any user interaction with ad view on Lockscreen. This interaction will be reported by
        See Also:
        This method should be called by app after
      • getPrimaryViewOfWidth

        public android.view.View getPrimaryViewOfWidth​(android.content.Context context,
                                                       android.view.View convertView,
                                                       android.view.ViewGroup parent,
                                                       int viewWidthInPixels)
        Method to return a native ad view. This method should be called only when the NativeAdEventListener#onAdLoadSucceeded(InMobiNative) callback was provided.
        Parameters:
        context - Context in which ad will be rendered.
        convertView - Recycled view provided by the Adapter.
        parent - The parent for the primary view
        Returns:
        a native ad view that is constructed by InMobi if ad load was successful, null otherwise.
      • getPrimaryViewOfWidth

        @Deprecated
        public android.view.View getPrimaryViewOfWidth​(android.view.View convertView,
                                                       android.view.ViewGroup parent,
                                                       int viewWidthInPixels)
        Deprecated.
        Parameters:
        convertView - Recycled view provided by the Adapter.
        parent - The parent for the primary view
        Returns:
        a native ad view that is constructed by InMobi if ad load was successful, null otherwise.
        See Also:
        NativeAdEventListener#onAdLoadSucceeded(InMobiNative)
      • getCustomAdContent

        public org.json.JSONObject getCustomAdContent()
      • getAdTitle

        public java.lang.String getAdTitle()
      • getAdDescription

        public java.lang.String getAdDescription()
      • getAdIconUrl

        public java.lang.String getAdIconUrl()
      • getAdLandingPageUrl

        public java.lang.String getAdLandingPageUrl()
      • getAdCtaText

        public java.lang.String getAdCtaText()
      • getAdRating

        public float getAdRating()
      • isAppDownload

        public boolean isAppDownload()
      • isVideo

        public java.lang.Boolean isVideo()
        This api provides information if the ad returned contains a video or not. It returns true if the ad contains a video and returns false vice versa. It will return null if this method is called in a wrong state, i.e., can be called only after the NativeAdEventListener#onAdLoadSucceeded(InMobiNative) callback is given.
        Returns:
        a Boolean if the ad returned contains a video or not
      • reportAdClickAndOpenLandingPage

        public void reportAdClickAndOpenLandingPage()
      • isReady

        public boolean isReady()
        Returns true if the native was loaded successfully and is ready to be shown.
        Returns:
      • getAdMetaInfo

        @Deprecated
        public org.json.JSONObject getAdMetaInfo()
        Deprecated.
        This method has been deprecated, please use AdMetaInfo.getBidInfo() in NativeAdEventListener#onAdFetchSuccessful(InMobiNative, AdMetaInfo) instead. Returns meta info about Ad if any such info is available otherwise returns empty JSONObject
        Returns:
        JSONObject
      • setExtras

        public void setExtras​(java.util.Map<java.lang.String,​java.lang.String> extras)
        Set any additional custom parameters that will be sent in the ad request.
        Parameters:
        extras - additional custom parameters
      • setKeywords

        public void setKeywords​(java.lang.String keywords)
        Set comma delimited keywords for targeting purpose
        Parameters:
        keywords - comma delimited keywords
      • setContentUrl

        public void setContentUrl​(java.lang.String contentUrl)
        Set the current context of the app.
        Parameters:
        contentUrl - - Represents the contentUrl of the app
      • destroy

        public void destroy()
        Destroy the Native ad view.

        Note This method must be called on the UI thread. Failure to do so will affect your ability to monetize with the InMobi Ad SDK.

      • getCreativeId

        @Deprecated
        public java.lang.String getCreativeId()
        Deprecated.
        This method has been deprecated, please use AdMetaInfo.getCreativeID() in NativeAdEventListener#onAdFetchSuccessful(InMobiNative, AdMetaInfo) instead. Returns creativeId if the Native ad was loaded successfully and creativeId is available otherwise returns empty string.
        Returns:
        String