AhriXV

Warper
Member
Joined
Aug 29, 2019
Messages
1
Reaction score
10
First Language
English
Primarily Uses
RMMV
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.png1618605595512.png1618605604179.png
 
Last edited:

BlueDragonLord

Blue Dragon L
Member
Joined
May 5, 2018
Messages
7
Reaction score
1
First Language
English
Primarily Uses
RMMV
Just tried it and it also works for me. It's wonderful to have total ad flow control.
 

LightAme

Artist
Veteran
Joined
Nov 6, 2015
Messages
35
Reaction score
17
First Language
English
Primarily Uses
N/A
Thank you!
Want to ask, is there any way for banner ads instead of interstitial ads?
 

RATISOFT

Villager
Member
Joined
Oct 25, 2015
Messages
25
Reaction score
15
First Language
Polish
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.
 
Last edited:

Raggon

Veteran
Veteran
Joined
Sep 29, 2018
Messages
66
Reaction score
46
First Language
english
Primarily Uses
RMMV
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);
    }
}
 

Latest Threads

Latest Profile Posts

You thought kids rooms were messy. Look at this.
Back in the house and I'm hungry
Yoshi!
DNPwhy.gif

You're using that item wrong... TwT

Trying to get the mechanics down for a cute, story-driven board game! I think I've accomplished dice movement, item effects, and activating a space's event when you land on it. Art is WIP. Hope to open a thread about the game soon!
My entire family and I have Covid... If it's this bad with the vaccine, without must be terrible. Stay safe, everyone. This thing is a doozy.

Forum statistics

Threads
118,527
Messages
1,116,649
Members
155,544
Latest member
Merodu
Top