MREC
MREC is 300x250 banner. This type can be useful if the application has a large free area for placing a banner in the interface.
You can use our demo MREC app as a reference project.
Check If Ad Is Loaded
You can check if the ad has been loaded before showing it. This method returns a boolean value indicating whether or not the MREC has been loaded.
- Kotlin
- Java
Appodeal.isLoaded(Appodeal.MREC)
Appodeal.isLoaded(Appodeal.MREC);
We recommend you always check whether an ad is available before trying to show it.
- Kotlin
- Java
if (Appodeal.isLoaded(Appodeal.MREC)) {
Appodeal.show(this, Appodeal.MREC)
}
if (Appodeal.isLoaded(Appodeal.MREC)) {
Appodeal.show(this, Appodeal.MREC);
}
Display
To display MREC, you need to call the following code in the activity:
- Add
com.appodeal.ads.MrecView
to your layout file:
<com.appodeal.ads.MrecView
android:id="@+id/appodealMrecView"
android:layout_width="300dp"
android:layout_height="250dp" />
- Set view id before the SDK initialization to show MREC:
- Kotlin
- Java
Appodeal.setMrecViewId(R.id.appodealMrecView)
Appodeal.setMrecViewId(R.id.appodealMrecView);
- Now you can show the MREC in the view specified (Make sure that the required view is on the screen):
- Kotlin
- Java
Appodeal.show(this, Appodeal.MREC)
Appodeal.show(this, Appodeal.MREC);
The method returns a boolean value indicating whether the call to the show method was passed to the appropriate SDK.
MrecView
should be on the top of the hierarchy and can not be overlapped by other views.Manual Caching
By default, auto caching is enabled: Appodeal SDK starts to load MREC right after the initialization method is called.
The next MREC ad starts to load after the previous one has been closed.
To disable automatic caching for MREC, use the code below before SDK initialization:
- Kotlin
- Java
Appodeal.setAutoCache(Appodeal.MREC, false)
Appodeal.setAutoCache(Appodeal.MREC, false);
To cache MREC use:
- Kotlin
- Java
Appodeal.cache(this, Appodeal.MREC)
Appodeal.cache(this, Appodeal.MREC);
Read more on manual caching in our FAQ.
Display MREC In Programmatically Created View
- Create MREC view and add view to your layout:
- Kotlin
- Java
val adView = Appodeal.getMrecView(this)
rootLayout.addView(adView)
MrecView adView = Appodeal.getMrecView(this);
rootLayout.addView(adView);
- Now you can show the MrecView in the view specified (Make sure that the required view is on the screen):
- Kotlin
- Java
Appodeal.show(this, Appodeal.MREC)
Appodeal.show(this, Appodeal.MREC);
The method returns a boolean value indicating whether the call to the show method was passed to the appropriate SDK.
MrecView
should be on the top of the hierarchy and can not be overlapped by other views.Callbacks
- Kotlin
- Java
Appodeal.setMrecCallbacks(object : MrecCallbacks {
override fun onMrecLoaded(isPrecache: Boolean) {
// Called when MREC is loaded
}
override fun onMrecFailedToLoad() {
// Called when MREC failed to load
}
override fun onMrecShown() {
// Called when MREC is shown
}
override fun onMrecShowFailed() {
// Called when MREC show failed
}
override fun onMrecClicked() {
// Called when MREC is clicked
}
override fun onMrecExpired() {
// Called when MREC is expired
}
})
Appodeal.setMrecCallbacks(new MrecCallbacks() {
@Override
public void onMrecLoaded(boolean isPrecache) {
// Called when MREC is loaded
}
@Override
public void onMrecFailedToLoad() {
// Called when MREC failed to load
}
@Override
public void onMrecShown() {
// Called when MREC is shown
}
@Override
public void onMrecShowFailed() {
// Called when MREC show failed
}
@Override
public void onMrecClicked() {
// Called when MREC is clicked
}
@Override
public void onMrecExpired() {
// Called when MREC is expired
}
});
All callbacks are called on the main thread.
Placements
Appodeal SDK allows you to tag each impression with different placement. To be able to use placements, you need to create them in Appodeal Dashboard. Read more about placements.
- Kotlin
- Java
Appodeal.show(this, Appodeal.MREC, "yourPlacementName")
Appodeal.show(this, Appodeal.MREC, "yourPlacementName");
If the loaded ad can't be shown in a specific placement, nothing will be shown. If auto caching is enabled, the SDK will start to cache another ad, which can affect display rate. To save the loaded ad for future use (for instance, for another placement), check if the ad can be shown before calling show method:
- Kotlin
- Java
if (Appodeal.canShow(Appodeal.MREC, "yourPlacementName")) {
Appodeal.show(this, Appodeal.MREC, "yourPlacementName")
}
if (Appodeal.canShow(Appodeal.MREC, "yourPlacementName")) {
Appodeal.show(this, Appodeal.MREC, "yourPlacementName");
}
You can configure your impression logic for each placement.
If you have no placements or call Appodeal.show
with a placement that
does not exist, the impression will be tagged with default
placement
with corresponding settings applied.
Placement settings affect ONLY ad presentation, not loading or caching.
Check If Ad Is Initialized
To check if MREC was initialized, you can use the method:
- Kotlin
- Java
Appodeal.isInitialized(Appodeal.MREC)
Appodeal.isInitialized(Appodeal.MREC);
Returns true
, if the MREC was initialized.
Check If Autocache Is Enabled
To check if autocache is enabled for MREC, you can use the method:
- Kotlin
- Java
Appodeal.isAutoCacheEnabled(Appodeal.MREC)
Appodeal.isAutoCacheEnabled(Appodeal.MREC);
Returns true
, if autocache is enabled for MREC.
Get Predicted eCPM
This method returns the expected eCPM for the cached ad. The amount is calculated based on historical data for the current ad unit.
- Kotlin
- Java
Appodeal.getPredictedEcpm(Appodeal.MREC)
Appodeal.getPredictedEcpm(Appodeal.MREC);
Activity "Paused" State Handling
We’ll automatically handle pause and resume state for already displayed MRECs on Activity on which they were displayed, however, we don’t restore displayed MRECs after Activity recreation (e.g. - orientation changes) and we don’t show MRECs in newly created Activities.
For display ads on newly created Activity just call Appodeal.show()
method if required:
- Kotlin
- Java
override fun onResume() {
super.onResume()
Appodeal.show(this, Appodeal.MREC)
}
@Override
public void onResume() {
super.onResume();
Appodeal.show(this, Appodeal.MREC);
}
This behavior can be changed by calling
Appodeal.setSharedAdsInstanceAcrossActivities(true)
(See more: Enable Shared View Ads Instance Across Activities Logic)
Hide
- Kotlin
- Java
Appodeal.hide(this, Appodeal.MREC)
Appodeal.hide(this, Appodeal.MREC);
Destroy
If you want to hide the MREC from all activities and clear the memory, call the code below:
- Kotlin
- Java
Appodeal.destroy(Appodeal.MREC)
Appodeal.destroy(Appodeal.MREC);
Enable Shared View Ads Instance Across Activities Logic
Appodeal SDK binds the Banner/MREC
to the Activity which was passed to the Appodeal.show
method.
To make it easier for you to manage View ads display logic across all Activities we added a new method in Appodeal class:
- Kotlin
- Java
Appodeal.setSharedAdsInstanceAcrossActivities(sharedAdsInstanceAcrossActivities: Boolean)
Appodeal.setSharedAdsInstanceAcrossActivities(boolean sharedAdsInstanceAcrossActivities);
- When this method is used with the
true
parameter, the SDK will show AdView on all new activities without calling additional code from your side. - If you want to control the display yourself, you can call the method with the
false
parameter.cautionIn this case, this parameter is false, be careful with changing orientation or moving to a new activity, the
Banner/MREC
will not be shown automatically, since it was bound to the previous activity. If you want to hide theBanner/MREC
, you need to call theAppodeal.hide()
method with the parameters of the activity to which theBanner/MREC
was bound.
You can also check the current state of this logic:
- Kotlin
- Java
Appodeal.isSharedAdsInstanceAcrossActivities()
Appodeal.isSharedAdsInstanceAcrossActivities();
Shared View Ads Instance Across Activities is disabled by default
Check Viewability
You can always check in logs if show was tracked and your ad is visible.
You will see the Mrec [Notify Shown] log if show was tracked successfully.
- Log
Appodeal com.example.app D Mrec [Notify Shown]