You have to first upload your app *without* ads, to get it approved on MobPartner. Once it is approved (takes a couple of days) you can start adding campaigns.
Once that’s done, you’re going to need to grab some URLs from here
:
When you are logged into MobPartner, click on Sites & Apps. Then in the app you want, click Banner. You should get a screen like the one above. I have highlighted the two main things you will need. The click URL (in yellow) and the image URL (in green.)
Now, on to AppInventor 2
In your app you are going to have to add a Clock, and an Activity Starter. The Clock can be found under “User Interface” and the Activity Starter can be found under “Connectivity”. As you can see in the image above, My Clock is named Clock1 and my Activity Starter is named openAd.
The clock should be configured like this:
The TimerInterval is set to 15000, which means it will fire every 15 seconds. This means the banner ad will change every 15 seconds. You can set this to be higher if you want… but I wouldn’t suggest you set it to be any lower.
The Activity Starter should look like this:
The Action should be: android.intent.action.VIEW
The DataURL should be something like this: http://c.mobpartner.mobi/?pool=49645&format=banner This is your click URL, which I highlighted in yellow above. Don’t use *this* exact URL, it is mine, you have to log into MobPartner to find yours.
Next you need to add a button. The button should have no text. Place the button where you want the advertisement to appear on the screen. I choose to put it inside a HorizantalArrangement so I could better format it.
On to the blocks!These are the blocks you need to make the ad function. The first one is changing the advertisement every time that the 15 seconds are up. The URL above is mine, the one you will use is your own image URL from MobPartner (highlighted in green above!)
The second block opens the link when the button is clicked.
If you run the app at this point you will notice that although it works, the button is blank for the first 15 seconds! So we need to do one more thing to set that up.
When the screen initiates, I do a lot of things. The ones that are important are below the hashed line. I am setting the button image to be my image URL (highlighted in green above). This means we won’t have to wait 15 seconds for our first ad. As you can see I also set the height and width of the banner here. You don’t necessarily have to do this, but you can