Class DynamicAds
java.lang.Object
com.pranavpandey.android.dynamic.ads.DynamicAds
Helper class to handle the ads related operations including the consent information.
It must be initialized once before accessing its methods.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns whether the app has completed the necessary steps for gathering updated user consent.void
Try to create a dynamic ad.static long
Returns the dynamic ad event count from the shared preferences.com.google.android.ump.ConsentForm
Get the consent form if available.com.google.android.ump.ConsentInformation
Get the consent information if available.com.google.android.ump.ConsentRequestParameters
Returns the consent request parameters required to load the consent information.int
Returns the status of the consent information.Returns the context used by this instance.Returns the main thread handler to publish results.static DynamicAds
Retrieves the singleton instance ofDynamicAds
.void
initializeAd
(DynamicAd dynamicAd, BaseAdListener adListener) Try to initialize the mobile ads.static void
initializeInstance
(Context context) Initialize ads when application starts.static boolean
isAdVisible
(DynamicAd dynamicAd) Returns whether the ad is visible to the user.boolean
Checks whether a consent form is available.boolean
Checks whether a consent form is visible to the user.boolean
Checks whether a consent information is available.boolean
Checks whether a consent is required from the user.boolean
Returns whether the mobile ads have been initialized.void
loadConsentForm
(BaseAdListener adListener, boolean force) Try to load the consent form.void
loadConsentInformation
(BaseAdListener adListener, boolean force) Try to request the consent information update.static void
onAdDestroy
(DynamicAd dynamicAd) Try to destroy the dynamic ad.static void
Increment the saved ad event count by one.static void
Try to pause the dynamic ad.static void
onAdResume
(DynamicAd dynamicAd) Try to resume the dynamic ad.void
Try to create a dynamic ad on main thread.void
Queue a dynamic ad to be reloaded later.void
Try to recreate all the queued ads.static void
Reset the dynamic ad event count.static void
setAdEventCount
(long eventCount) Save the dynamic ad event count into the shared preferences.void
setConsentRequestParameters
(com.google.android.ump.ConsentRequestParameters consentRequestParameters) Set the consent request parameters required to load the consent information.void
showConsentForm
(BaseAdListener adListener) Try to show the consent form.
-
Method Details
-
initializeInstance
Initialize ads when application starts.Must be initialized once.
- Parameters:
context
- The context to retrieve resources.
-
getInstance
Retrieves the singleton instance ofDynamicAds
.Must be called before accessing the public methods.
- Returns:
- The singleton instance of
DynamicAds
.
-
getAdEventCount
public static long getAdEventCount()Returns the dynamic ad event count from the shared preferences.- Returns:
- The dynamic ad event count from the shared preferences.
- See Also:
-
setAdEventCount
public static void setAdEventCount(long eventCount) Save the dynamic ad event count into the shared preferences.- Parameters:
eventCount
- The ad event count to be set.- See Also:
-
resetAdEventCount
public static void resetAdEventCount()Reset the dynamic ad event count. -
onAdEvent
public static void onAdEvent()Increment the saved ad event count by one.- See Also:
-
getContext
Returns the context used by this instance.- Returns:
- The context to retrieve the resources.
-
getHandler
Returns the main thread handler to publish results.- Returns:
- The main thread handler to publish results.
-
isInitialized
public boolean isInitialized()Returns whether the mobile ads have been initialized.- Returns:
true
if the mobile ads have been initialized.
-
getConsentInformation
Get the consent information if available.- Returns:
- The consent information if available.
-
getConsentForm
Get the consent form if available.- Returns:
- The consent form if available.
-
isConsentInformationAvailable
public boolean isConsentInformationAvailable()Checks whether a consent information is available.- Returns:
true
if a consent information is available.
-
isConsentFormAvailable
public boolean isConsentFormAvailable()Checks whether a consent form is available.- Returns:
true
if a consent form is available.
-
isConsentFormVisible
public boolean isConsentFormVisible()Checks whether a consent form is visible to the user.- Returns:
true
if a consent form is visible to the user.
-
getConsentRequestParameters
Returns the consent request parameters required to load the consent information.- Returns:
- The consent request parameters required to load the consent information.
-
setConsentRequestParameters
public void setConsentRequestParameters(@Nullable com.google.android.ump.ConsentRequestParameters consentRequestParameters) Set the consent request parameters required to load the consent information.- Parameters:
consentRequestParameters
- The parameters to be set.Use
null
to set the default parameters.
-
getConsentStatus
public int getConsentStatus()Returns the status of the consent information.- Returns:
- The status of the consent information.
-
canRequestAds
public boolean canRequestAds()Returns whether the app has completed the necessary steps for gathering updated user consent.- Returns:
true
if the app has completed the necessary steps for gathering updated user consent.
-
isConsentRequired
public boolean isConsentRequired()Checks whether a consent is required from the user.- Returns:
true
if a consent is required from the user.
-
recreateAds
public void recreateAds()Try to recreate all the queued ads.
-