Accessing the AdMob widget from inside the app

Visto 21 veces
Saltar al primer mensaje no leído

Zoltan Fedor

no leída,
22 ene 2017, 15:50:1822/1/17
a Kivy users support
Hi,

I have successfully integrated AdMob into my Android app using the idea from http://www.theseusmedia.com/blogs/code/post/1
Because that link was a bit outdated, I had to make some changes, but now AdMob ads show up correctly in the top section of the app, overlaying the top of the app - which is great.

The problem I have, is that in same cases I would temporarily need to hide the AdMob widget - for example when the user opens the settings (config) panel, the buttons of the settings panel are not available because they are stuck behind the ad's widget (which is on the top section of the app).

This is why I am trying to access the AdMob widget from the app (which I added in the PythonActivity.java), so temporarily I can hide it when the settings (config) panel comes up. But I just can't seem to find this widget in the widget tree, doesn't matter where I try.

Anybody has any idea how to access this widget from inside the app? Is that even possible?

Below is the code I have added to the /org/kivy/android/PythonActivity.java file to have the AdMob widget added to my app. This "adView" widget I am trying to access from the app.

    if (mLayout != null) {
        Log.v(TAG, "Setting up AdMob...");
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);
        lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        lp.addRule(RelativeLayout.CENTER_IN_PARENT);
        AdView adView = new AdView(this);
        adView.setAdUnitId("YOUR_UNIT_ID");
        adView.setAdSize(AdSize.BANNER);
        adView.setLayoutParams(lp);
        mLayout.addView(adView);
        AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice("YOUR_TEST_DEVICE") // Replace with your test device id
            .build();
        
        // to confirm that the test device setting has worked
        boolean isTestDevice = adRequest.isTestDevice(this);
        Log.v(TAG, "Is this an AdMob Test Device ? "+isTestDevice); // to confirm it worked
        adView.loadAd(adRequest);
    }

Thanks
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos