Ads (Admob) in RPG Maker MV

All credits to waffs702 + his tutorial (https://github.com/waffs702/mv_to_android/wiki/インタースティシャル広告)

Hi everyone, I wanted to share a way that you can add admob to your games.

First of all, download the Android Studio project to turn your RPGMV project into an android application.


In this case I will use an example with an interstitial ad.

Go to the following link and download the following plugins:


-MZxNativeCore.js
-MVxNativeInterstitialAd.js

Install the plugins.

1618605437975.png


Go to the common events of your project.

1618605450262.png


You can optionally add two messages to check if the ads work if simply creating the common events without instructions is not enough.

1618605460412.png


Create an event and add the following statement: MVxNativeInterstitialAd X Y, X = Common event for success and Y = Common event for failure.

1618605477694.png


Deploy your project.

1618605488188.png


Go to the mv_to_android-master folder, open app folder and create a folder called htmlSource.

1618605497122.png


Move the files from your game's www folder to the htmlSource folder.

1618605507555.png


Open mv_to_android-master in Android Studio.

1618605517540.png


Use the view in "project" and go to app\src\main\res\values\strings.xml

1618605525826.png

1618605531985.png


Inside string.xml you will find:

The name of your game: <string name="app_name">game name</string>
The id of your application in admob: <string name="ad_application_id">id app</string>
The id of your ads:
<string name="ad_rewarded_unit_id">id rewarded ad</string>
<string name="ad_interstitial_id">id insterstitial ad</string>



1618605541364.png


You can try test ads in https://developers.google.com/admob/android/test-ads#sample_ad_units or head over to admob and test your own ads.

1618605549904.png

1618605559141.png


>Build apk

If you do not see any ads wait at least half an hour, they usually do not appear instantly.
That would be all.
1618605576033.png
1618605595512.png
1618605604179.png
Nice tutorial and it actually works!
Just tried it and it also works for me. It's wonderful to have total ad flow control.
love u too
Thank you!
Want to ask, is there any way for banner ads instead of interstitial ads?
Hey,

this works perfect, but if I'm using this Android Studio project, external links doesn't work correctly.

I call them by script in common event open.window() function with _blank. And still they're opening in the same activity window.

So my question is, anyone have any idea what I need to modify in MainActivity or ScriptHandler to open links as a new activity?



EDIT:

Anyway, just figured it out. I will share my solution but I am not sure I'll put here every changes I've made:

Just after (in MainActivity):
Java:
        webView.getSettings().setDomStorageEnabled(true);
        webView.getSettings().setAllowUniversalAccessFromFileURLs(true);

Add:
Java:
        webView.getSettings().setSupportMultipleWindows(true);
        webView.getSettings().setAllowFileAccess(true);
        webView.getSettings().setAllowContentAccess(true);
        webView.setWebChromeClient(new ChromeClient());

Then somewhere in the MainActivity:
Java:
   private class ChromeClient extends WebChromeClient {
        @Override
        public boolean onConsoleMessage(ConsoleMessage consoleMessage){
            if ("Scripts may close only the windows that were opened by it.".equals(consoleMessage.message())) {
                if (webView.getContext() instanceof MainActivity) {
                    ((MainActivity)webView.getContext()).finish();
                }
            }
            return super.onConsoleMessage(consoleMessage);
        }
        @Override
        public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
            WebView dumbWV = new WebView(view.getContext());
            dumbWV.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageStarted(WebView view, String url, Bitmap favicon) {
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    view.getContext().startActivity(browserIntent);
                }
            });
            ((WebView.WebViewTransport) resultMsg.obj).setWebView(dumbWV);
            resultMsg.sendToTarget();
            return true;
        }

    }

It works for me and now, if I call website from my script call, It opens Chrome as second activity. If I call Google Play app url, it opens Play Store.
anyone figured out how to get main activity to go back to game after ad without restarting the game?

Code:
package com.example.mv_to_mobile_android;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.appcompat.app.AppCompatActivity;
import androidx.webkit.WebViewAssetLoader;

public class MainActivity extends AppCompatActivity {
    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        hideNavigationBar();

        webView = (WebView) findViewById(R.id.webView);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setDomStorageEnabled(true);
        webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
        webView.getSettings().setSupportMultipleWindows(true);
        webView.getSettings().setAllowFileAccess(true);
        webView.getSettings().setAllowContentAccess(true);

        ScriptHandler scriptHandler = new ScriptHandler();
        Handler handler = new Handler();
        scriptHandler.setActivity(MainActivity.this);
        scriptHandler.setHandler(handler);
        scriptHandler.setWebView(webView);
        webView.addJavascriptInterface(scriptHandler, "MVZxAndroidHandlers");

        final WebViewAssetLoader assetLoader = new WebViewAssetLoader.Builder()
                .addPathHandler("/htmlSource/", new WebViewAssetLoader.AssetsPathHandler(this))
                .addPathHandler("/assets/", new WebViewAssetLoader.AssetsPathHandler(this))
                .addPathHandler("/res/", new WebViewAssetLoader.ResourcesPathHandler(this))
                .build();
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
                return assetLoader.shouldInterceptRequest(request.getUrl());
            }
        });

        String path = "https://appassets.androidplatform.net/htmlSource/index.html";
        this.webView.loadUrl(path);

        Advertisement.initAd();
        Advertisement.loadRewardedAd(null);
        Advertisement.loadInterstitialAd();
    }

    @Override
    protected void onResume() {
        super.onResume();
        hideNavigationBar();
    }

    private void hideNavigationBar() {
        // Hide both the navigation bar and the status bar.
        View decoView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
        decoView.setSystemUiVisibility(uiOptions);
    }
}
Apparently the plugins don't work on newer versions of RMZ. Anyone willing to update the scripts and get paid for it? Please send me a private message.
Fyi including ads in your game makes it commercial for licence purposes even if the game itself is free.
No problem with that as at least I have all licenses paid to the plugin developers.
Hi all!
I have a problem. The plugin doesn't work for me on RPG MV 🙁 (see the screenshot).
When I open the game, it shows the message in attachment.
Can anyone help me?
It works! But I have an issue:
the game restarts when it shows a "portrait video ad".
When it shows a "landscape video ad" it works perfectly instead.
Can someone help me please?
My game is in landscape mode.
It works! But I have an issue:
the game restarts when it shows a "portrait video ad".
When it shows a "landscape video ad" it works perfectly instead.
Can someone help me please?
My game is in landscape mode.

@aliensanfo you forgot to add the plugin to the plugins folder... eh oops should have read that u found that out. and i have the same problem by the way. im thinking of not using the plugin anymore. there`s one where you can charge in game that i will probably go with.
I have the plug ins on my MZ already

1705935325607.png


However when I try to call them out in the event, it does not show up for me. anyone who can help me with this?

1705935417500.png


Hi @Atria you mentioned that you have an alternative where you can charge in game? What is it and maybe I can go with that if I cannot make this plug in work on my MZ. Maybe because I am using a new version that is why it doesn't work on my end anymore.

Thanks.
hey @dinosabella i still use this plugin. have not had a chance to update mobile etc or just port to the buy plugin but these are my bookmarks for the other plugins i tried i beleive.

https://hackmd.io/@Mirai/RPGMakerMVMZ-Android_eng

and


https://forums.rpgmakerweb.com/inde...l-android-client-with-in-app-purchase.105187/

Original thread: https://forums.rpgmakerweb.com/threads/ads-admob-in-rpg-maker-mv.135551/