...
The MobileFusePullTabAd
class provided by the MobileFuse SDK will handle the loading, display, and interactivity of the pull-tab creative. It is similar in implementation to MobileFuse interstitial ads.
Info |
---|
Note: Ensure that critical sections of your app, for example buttons or text, do not sit within the left margin of the screen when displaying a pull-tab ad. |
...
Next, add a listener - the listener will allow you to receive events from the ad unit. The pull-tab ad has some additional callbacks for pull-tab specific events.
Code Block |
---|
|
pullTabAdpullTab.setListener(new MobileFusePullTabAd.Listener() {
@Override
public void onAdClosed() {
// The pull-tab ad has been dismissed and closed
}
@Override
public void onAdPulled() {
// The pull-tab ad has been pulled and expanded into a full-screen interstitial style view
}
@Override
public void onAdLoaded() {
// Called when the pull tab ad has been loaded and is ready to be displayed
}
@Override
public void onAdNotFilled() {
// The server responded with no fill (no ad available)
}
@Override
public void onAdRendered() {
// The pull-tab ad has been rendered and is displaying to the user
}
@Override
public void onAdClicked() {
// Called when the user clicks the pull-tab ad
}
@Override
public void onAdExpired() {
// This ad has expired and can no longer be displayed to the user - load a new ad
}
@Override
public void onAdError(AdError adError) {
// An error occurred, examine the adError argument to determine the problem
}
}); |
...
Note |
---|
Note: The pull-tab will render a tab in the left 10% of screen space. Be sure that when a pull-tab ad is displayed that you don’t place important UI components or buttons within this area. You may want to add padding to the left side of your activity to shift your UI away from the ad slightly. See the sample code for an example. |
Code Block |
---|
|
pullTabAd.showAd(); |
...
Code Block |
---|
|
if (pullTabAd.isLoaded()) {
// The ad is ready to be displayed!
} |
Sample Code
The following sample shows an activity that will initialize and then immediately display the pull-tab ad:
...
Java
Expand |
---|
|
Code Block |
---|
import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.widget.Toast;
import com.mobilefuse.sdk.AdError;
import com.mobilefuse.sdk. | PullTabAdMobileFuse;
import com.mobilefuse.sdk. | PullTabAdListenerMobileFusePullTabAd;
import com.mobilefuse.sdk. | MobileFuseMobileFuseSettings;
import com.mobilefuse.sdk.SdkInitListener;
import com.mobilefuse.sdk.privacy. | PrivacyPreferencesMobileFusePrivacyPreferences;
public class MainActivity extends Activity {
final int publisherId = 0;
final int appId = 0;
final String pullTabPlacementId = "000000";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Set up the user's privacy preferences before init:
| PrivacyPreferences.Builder privacyPrefs = MobileFuse.setPrivacyPreferences(
new | PrivacyPreferencesMobileFusePrivacyPreferences.Builder() | ;privacyPrefssetIabConsentString("...");MobileFusesetPrivacyPreferences(privacyPrefs.build());setUsPrivacyConsentString("1YNN")
| StringappId="0000_00000";StringpullTabAdPlacement="000000"ctxactivity = this;
MobileFuse.init( | ctxactivity, publisherId, appId, new SdkInitListener() {
@Override
public void onInitSuccess() {
Toast.makeText( | ctxsuccessSuccess", Toast.LENGTH_SHORT).show();
| PullTabAd ad
// Create a new interstitial ad and display it immediately
MobileFusePullTabAd pullTab = new | PullTabAdctxpullTabAdPlacementadPullTabAdListenerMobileFusePullTabAd.Listener() {
@Override public void onAdLoaded() {
// Show the ad as soon as it has loaded:
pullTab.showAd();
}
@Override public void | onAdLoaded Show the ad as soon as it has loaded Set our left margin to 10% of the width
setAppLeftMarginFraction(0.1f);
}
@Override public void onAdClosed() {
// Reset our margin:
| ad.showAdsetAppLeftMarginFraction(0f);
}
@Override public void | onAdUnavailableonAdPulled() { }
@Override public void | onAdCompleteonAdNotFilled() { }
@Override public void | onAdShowingonAdClicked() { }
@Override public void | onAdClickedonAdExpired() { }
@Override public void onAdError(AdError adError) { }
});
// Send the | RequestloadingofadadpullTab.loadAd();
}
@Override
public void onInitError() {
Toast.makeText( | ctxfailedFailed", Toast.LENGTH_SHORT).show();
}
});
}
private void setAppLeftMarginFraction(float fraction) {
// Example: Calculating the left margin as a fraction of the entire screen width:
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics outMetrics = new DisplayMetrics ();
display.getMetrics(outMetrics);
float density = getResources().getDisplayMetrics().density;
float dpWidth = outMetrics.widthPixels / density;
findViewById(R.id.main_view_container).setPadding((int)(dpWidth * fraction), 0, 0, 0);
}
} |
|
Kotlin
Expand |
---|
|
Code Block |
---|
import android.app.Activity
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.Display
import android.view.View
import android.widget.Toast
import com.mobilefuse.sdk.AdError
import com.mobilefuse.sdk.MobileFuse
import com.mobilefuse.sdk.MobileFusePullTabAd
import com.mobilefuse.sdk.SdkInitListener
import com.mobilefuse.sdk.privacy.MobileFusePrivacyPreferences
class MainActivity : Activity() {
private val publisherId = 0
private val appId = 0
private val pullTabPlacementId = "000000"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Set up the user's privacy preferences before init:
MobileFuse.setPrivacyPreferences(
MobileFusePrivacyPreferences.Builder()
.setSubjectToCoppa(false)
.setUsPrivacyConsentString("1YNN")
.build()
)
val activity: Activity = this
MobileFuse.init(activity, publisherId, appId, object : SdkInitListener {
override fun onInitSuccess() {
Toast.makeText(activity, "SDK Init Success", Toast.LENGTH_SHORT).show()
// Create a new interstitial ad and display it immediately
val pullTab = MobileFusePullTabAd(activity, pullTabPlacementId)
pullTab.setListener(object : MobileFusePullTabAd.Listener {
override fun onAdLoaded() {
// Show the ad as soon as it has loaded:
pullTab.showAd()
}
override fun onAdRendered() {
// Set our left margin to 10% of the width
setAppLeftMarginFraction(0.1f)
}
override fun onAdClosed() {
// Reset our margin:
setAppLeftMarginFraction(0f)
}
override fun onAdPulled() {}
override fun onAdNotFilled() {}
override fun onAdClicked() {}
override fun onAdExpired() {}
override fun onAdError(adError: AdError?) {}
})
// Send the ad request to the server:
pullTab.loadAd()
}
override fun onInitError() {
Toast.makeText(activity, "SDK Init Failed", Toast.LENGTH_SHORT).show()
}
})
}
private fun setAppLeftMarginFraction(fraction: Float) {
// Example: Calculating the left margin as a fraction of the entire screen width:
val display: Display = windowManager.defaultDisplay
val outMetrics = DisplayMetrics()
display.getMetrics(outMetrics)
val density = resources.displayMetrics.density
val dpWidth = outMetrics.widthPixels / density
findViewById<View>(R.id.main_view_container).setPadding((dpWidth * fraction).toInt(), 0, 0, 0)
}
} |
|