Native Ads

With the release of MAS 4.6, you can now use Native Ads in your games! Here are a few things you need to know in order to get started with this ad type:

  • Native ads in MAS are available in 3 sizes: Small, Medium, or Custom. Small has a ratio of 3:1, and Medium has a ratio of 6:5. See the table below for recommended sizes.
  • Custom means you show a Native Ad in a way that’s consistent with its existing UI design, please click here to follow the custom native ad integration instruction.
  • Currently, you may only use 1 size of Native Ad for your game, which you can specify during the submission of your game. Should you need to change the size, please contact the support team via the support chat.

Small Size (3:1) Medium Size (6:5)
300 x 100* 600 x 500
*You can leave width alone and let it match parent, or manually set it.

1. Add Yodo1MasNativeAdView to the layout

The first step toward displaying a native is to place Yodo1MasNativeAdView in the layout for the Activity or Fragment in which you’d like to display it. The easiest way to do this is to add one to the corresponding XML layout file. Here’s an example that shows an activity’s Yodo1MasNativeAdView:

				
					...
	<com.yodo1.mas.nativeads.Yodo1MasNativeAdView 
		xmlns:masads="http://schemas.android.com/apk/res-auto"
		android:id="@+id/yodo1_mas_native"
		android:layout_width="match_parent"
		android:layout_height="300dp"
		android:layout_gravity="center_horizontal|top"/>
...
				
			

You can alternatively create Yodo1MasNativeAdView programmatically:

Yodo1MasNativeAdView nativeAdView =
new Yodo1MasNativeAdView(this);
nativeAdView.setLayoutParams(new
ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp2px(300)));
// TODO: Add nativeAdView to your view hierarchy.
val nativeAdView = Yodo1MasNativeAdView(this)
nativeAdView.setLayoutParams(ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, dp2px(300)))
// TODO: Add nativeAdView to your view hierarchy.

2. Load an ad

Once the Yodo1MasNativeAdView is in place, the next step is to load an ad. That’s done with the loadAd() method in the Yodo1MasNativeAdView class.

Here’s an example that shows how to load an ad in the onCreate() method of an Activity:

package...
import...
import com.yodo1.mas.Yodo1Mas;
import com.yodo1.mas.nativeads.Yodo1MasNativeAdView;
public class MainActivity extends AppCompatActivity {
private Yodo1MasNativeAdView nativeAdView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Yodo1Mas.getInstance().init(this, "YourAppKey", new
Yodo1Mas.InitListener() { @Override public void onMasInitSuccessful() { }
@Override
public void onMasInitFailed(@NonNull Yodo1MasError error) { } });
nativeAdView = findViewById(R.id.yodo1_mas_native); nativeAdView.loadAd(); } }
package...
import...
import com.yodo1.mas.Yodo1Mas;
import com.yodo1.mas.nativeads.Yodo1MasNativeAdView;
class MainActivity : AppCompatActivity() {
lateinit var nativeAdView : Yodo1MasNativeAdView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Yodo1Mas.getInstance().init(this, "YourAppKey", object : Yodo1Mas.InitListener
{ override fun onMasInitSuccessful() { 
Toast.makeText(this@MainActivity, "[Yodo1 Mas] Successful initialization", Toast.LENGTH_SHORT).show() }
override fun onMasInitFailed(error: Yodo1MasError)
{ Toast.makeText(this@MainActivity, error.message, Toast.LENGTH_SHORT).show() } })
nativeAdView = findViewById(R.id.yodo1_mas_native) nativeAdView.loadAd() } }

That’s it! Your app is now ready to display native ads.

3. Ad events

To further customize the behavior of your ad, you can hook onto a number of events in the ad’s lifecycle: loading, opening, closing, and so on. You can listen for these events through the Yodo1MasNativeAdListener class.

package...
import...
import com.yodo1.mas.Yodo1Mas;
import com.yodo1.mas.nativeads.Yodo1MasNativeAdListener;
import com.yodo1.mas.nativeads.Yodo1MasNativeAdView;
public class MainActivity extends AppCompatActivity {
private Yodo1MasNativeAdView nativeAdView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Yodo1Mas.getInstance().init(this, "YourAppKey", new Yodo1Mas.InitListener() {
@Override public void onMasInitSuccessful() { }
@Override public void onMasInitFailed(@NonNull Yodo1MasError error) { } });
nativeAdView = findViewById(R.id.yodo1_mas_native);
nativeAdView.setAdListener(new Yodo1MasNativeAdListener() {
@Override public void onNativeAdLoaded(Yodo1MasNativeAdView nativeAdView) {
// Code to be executed when an ad finishes loading. 
}
@Override public void onNativeAdFailedToLoad(Yodo1MasNativeAdView nativeAdView,
@NonNull Yodo1MasError error) { 
// Code to be executed when an ad request fails. 
} }); nativeAdView.loadAd(); } }
package...
import...
import com.yodo1.mas.Yodo1Mas;
import com.yodo1.mas.nativeads.Yodo1MasNativeAdListener;
import com.yodo1.mas.nativeads.Yodo1MasNativeAdView;
class MainActivity : AppCompatActivity() {
lateinit var nativeAdView : Yodo1MasNativeAdView override
fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) setContentView(R.layout.activity_main)
Yodo1Mas.getInstance().init(this, "YourAppKey", object : Yodo1Mas.InitListener {
override fun onMasInitSuccessful() {
Toast.makeText(this@MainActivity,
"[Yodo1 Mas] Successful initialization", Toast.LENGTH_SHORT).show() }
override fun onMasInitFailed(error: Yodo1MasError) { 
Toast.makeText(this@MainActivity, error.message, Toast.LENGTH_SHORT).show() } })
nativeAdView = findViewById(R.id.yodo1_mas_native) 
nativeAdView.setAdListener(object : Yodo1MasNativeAdListener {
override fun onNativeAdLoaded(nativeAdView: Yodo1MasNativeAdView?) {
// Code to be executed when an ad finishes loading.
}
override fun onNativeAdFailedToLoad(nativeAdView: Yodo1MasNativeAdView?, error: Yodo1MasError) { 
// Code to be executed when an ad request fails.
} }) nativeAdView.loadAd() } }

CONTENTS