5

So I have a project (module really since I'm using IntelliJ, but I'll use Eclipse terms) with Activity (Let's call it X) which loads an AdView and it all works just fine. Now I have another Activity (let's call it Y) which opens after certain actions, that Activity is inside a library project. Activity Y opens just fine and works well but the AdView I add to it never has anything in it, it is just just blank. Here are some odd messages I see on the logs:

 I/Ads﹕ Starting ad request.
 I/webclipboard﹕ clipservice: android.sec.clipboard.ClipboardExManager@4293f940
 W/ResourceType﹕ Requesting resource 0x7f0b000e failed because it is complex
 E/GooglePlayServicesUtil﹕ The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
 I/Adreno200-EGLSUB﹕ <ConfigWindowMatch:2087>: Format RGBA_8888.
 onSizeChanged - w:640 h:100
 W/ResourceType﹕ Requesting resource 0x7f0b000e failed because it is complex
 E/GooglePlayServicesUtil﹕ The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
 W/ResourceType﹕ Requesting resource 0x7f0b000e failed because it is complex
 E/GooglePlayServicesUtil﹕ The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.

These two messages happen later, after a bit of time (close to the 60 seconds):

 W/Ads﹕ Timed out waiting for WebView to finish loading.
 I/Ads﹕ Scheduling ad refresh 60000 milliseconds from now.
 W/Ads﹕ Failed to load ad: 2

And here is the code I use to create the AdView:

    adView = new AdView(this);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId(id);
    buttonsAndSeekbarLayout.addView(adView);
    final AdRequest.Builder builder = new AdRequest.Builder();

    AdRequest adRequest = builder.build();
    // Start loading the ad in the background.
    adView.loadAd(adRequest);

I should also mention that I am using other parts of the Google Play Services on that library project so I think it is configured correctly.

Thanks.

EDIT: I should mention that even if I add the adView on the xml it is still just blank!

EDIT2: Added some extra messages above. Also I noticed this message which after doing a search seems to be AdView related:

    D/WebKit﹕ SQLite database failed to load from /FileSyetmQuota.db

EDIT3: I found something odd. I added in app purchase to that screen, when the purchase is done, right before I remove the ad (because of the purchase), it shows up for a split of a second.

casolorz
  • 8,486
  • 19
  • 93
  • 200
  • Your logs show "Starting ad request". You should also have log showing "Ad request failed" or " Loading ad" or similar. Show that. – William Mar 30 '14 at 09:50
  • You are right, I found another two messages I haven't seen before and that don't show up on every request. `W/Ads﹕ Failed to load ad: 2` and `W/Ads﹕ Timed out waiting for WebView to finish loading.` – casolorz Mar 30 '14 at 14:26
  • i'd say the key is " E/GooglePlayServicesUtil﹕ The Google Play services resources were not found. Check your project configuration to ensure that the resources are included. " – rupps Mar 31 '14 at 20:19
  • They are there. I'm making a Chromecast app and this Library uses it heavily and it requires Google Play Services and that part is working just fine. – casolorz Mar 31 '14 at 23:38
  • Does you library project Y have the Google Play services stuff added to it? – Red Cricket Apr 02 '14 at 04:11
  • Yes, I've tried directly and indirectly (through another project dependency) and like I said, other parts of Play Services are working just fine on that project Y. – casolorz Apr 02 '14 at 13:46

3 Answers3

0
  1. E/GooglePlayServicesUtil﹕ The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.. Ignore that message, it appears even when you've running your GP services correctly, that's not the issue.

  2. The code part where you create your AdView and load an ad is perfect, that's neither the issue (I'm running exactly the same code on several projects and it works).

  3. Having in account the above, my bets are just two:

    • Somehow, the library project is interfering with the loading of the ad. Ad loading has a timeout, if you're doing some hard work, probably there's no time enough to load the ad and it times-out, so probably that's why you're seeing the Timed out waiting for WebView to finish loading. message. In this case, try putting the ad loading within a Thread (or an AsyncTask).

    • A layout rendering issue. You have to check whether the Ad has enough space to show up, i.e., 640 in width x 100 in height minimally. If you don't have that space, the ad won't show up.

---- EDIT ----

To run the code within a Thread, use this code:

new Thread(
  new Runnable() {
    @Override
    public void run() {
      adView = new AdView(this);
      adView.setAdSize(AdSize.BANNER);
      adView.setAdUnitId(id);

      // This will ensure it is run within the main UI.
      runOnUiThread(new Runnable() {
        public void run() {
          buttonsAndSeekbarLayout.addView(adView);
        }
      });

      final AdRequest.Builder builder = new AdRequest.Builder();

      AdRequest adRequest = builder.build();
      // Start loading the ad in the background.
      adView.loadAd(adRequest);
    }
  }
}).start();
nKn
  • 13,691
  • 9
  • 45
  • 62
  • Thanks for the help unfortunately the size doesn't make a difference, I even tried giving it the whole width of the device. Also the ad added programatically does take the space it is supposed to take, it is just blank. Regarding the library, I don't know what I could be doing in it to prevent the ad from loading, the library itself uses play services for other stuff and that works just fine. – casolorz Apr 01 '14 at 18:56
  • For the first guess: Just try putting the code of loading dynamically the ad in your question within a `Thread` and try seeing if that loads or not the ad. If you need help with this I'll include an example. – nKn Apr 01 '14 at 19:00
  • So I've tried putting it on a thread but all the ui actions require it to be on the ui thread, including `loadAd`. Also I've noticed this message a lot `Ad is not visible. Not refreshing ad.` but I've tried calling setVisibility as well as resume to make sure it is running but it doesn't change anything. – casolorz Apr 01 '14 at 19:21
  • Have a look at my updated answer. For the message you're seeing, I think it's worthy reading this: https://groups.google.com/forum/#!topic/google-admob-ads-sdk/jz-ZQh86lm0 – nKn Apr 01 '14 at 19:27
  • But in my case the AdView is just being created, I haven't paused or done anything yet. – casolorz Apr 01 '14 at 20:45
  • Have you tried using the code I updated in my answer? Note the `runOnUiThread()` part: You can include there anything that has something to do with updating some `View` in the UI thread. This way you can test whether it makes some difference or not. – nKn Apr 01 '14 at 21:29
  • Are you talking about the onPause code on that discussion? – casolorz Apr 01 '14 at 22:08
  • I found something odd. I added in app purchase to that screen, when the purchase is done, right before I remove the ad (because of the purchase), it shows up for a split of a second. – casolorz Apr 02 '14 at 04:04
  • In my yesterday's comment I was talking about 2 different things, one is the `Thread` part and the other was the `onPause()` and `onResume()` part. Now I refer to the first one, just try to include the `Thread` as I wrote, prior to load anything else. This will start a separate thread and load it paralelly to any other code you might have. This way you can know if it has something to do with the performance of that part of the code, if the ad loads it's definitely a performance issue. – nKn Apr 02 '14 at 07:28
  • Ohh yeah I had already tried the thread thing, didn't help. My code was pretty similar to yours except I had loadAd also in a `runOnUiThread` otherwise it complained. – casolorz Apr 02 '14 at 13:44
  • One stupid thing but also worth mentioning, did you include the `` line in your Manifest? – nKn Apr 04 '14 at 07:50
  • Yeap. And like I said, this is working fine on the first activity that loads ads. I have also recently discovered it has nothing to do with the library project, it happens on any activity I try to load ads after the first main activity. – casolorz Apr 04 '14 at 12:23
  • For what I've been reading, the `Timed out waiting for ad response.` usually is due to connectivity problems, probably slow connections. Could it be that the `WebView` is taking too much to load the content for the connection you're using and the ad doesn't get loaded? The timeout seems to be 5 seconds, if the ad doesn't manage to get loaded in that time, it times out. – nKn Apr 04 '14 at 13:04
  • Also have a look at this one: http://stackoverflow.com/questions/10234762/admob-on-multiple-activities – nKn Apr 04 '14 at 13:12
  • All that code is doing is creating a common method for handling the adview creation, and visibility changes, or am I reading it wrong? – casolorz Apr 04 '14 at 15:48
  • You're right, disregard that link as it's not doing anything new, I thought it was. One question: Have tried this code adding a Test Device Id via `.setTestDevice(...)`? Or if you're already doing, did you tried removing it? – nKn Apr 04 '14 at 16:04
0

hey please try to load ads like bellow example

first update your Google play lib to 4.3

The easiest way to incorporate an ad is to simply define your AdView as you would any other part of your res/layout/main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:ads="http://schemas.android.com/apk/res-auto"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent">
<com.google.android.gms.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="MY_AD_UNIT_ID"
                     ads:adSize="BANNER"/>
</LinearLayout>

you must replace MY_AD_UNIT_ID with your AdMob ad unit ID.

To fetch ads, look up the AdView as a resource via findViewById, create an AdRequest, and invoke loadAd:

import com.google.android.gms.ads.*;

public class BannerExample extends Activity {
   @Override
  public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);

     // Look up the AdView as a resource and load a request.
     AdView adView = (AdView)this.findViewById(R.id.adView);
     AdRequest adRequest = new AdRequest.Builder().build();
     adView.loadAd(adRequest);
   }
}
Ando Masahashi
  • 3,112
  • 2
  • 24
  • 41
  • I've tried the xml route as well and that didn't help, same issue, blank space where the ad should be, I should also be clear, I know the ad space is being taken because it is displacing other views on my linear layout. – casolorz Apr 02 '14 at 13:49
0

Figured it out, in my code I call webViewInstance.pauseTimers() and apparently that applies to all web views.

casolorz
  • 8,486
  • 19
  • 93
  • 200