1

I am attempting to implement the AdMob with Google Play Services. So far I have the default test banner appearing but I want to try some of the test ads.

I read that the emulator (AVD) must have Google APIs 16 or 17 as the target in order to test the AdMob however when I create a device that has this as target the emulator fails to load ( i left it for a good 20 minutes still has not loaded yet :( I just see the flashing android logo

This my AVD device

enter image description here

This is my AdFragment class that contains all the code related to the advertisements

public class AdFragment extends Fragment 
{

    private AdView mAdView;

    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container,  Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        return inflater.inflate(R.layout.fragment_ad, container, false);

    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) 
    {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);
        mAdView = (AdView)getView().findViewById(R.id.adView);

        AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
        .build();


         // Start loading the ad in the background.
        mAdView.loadAd(adRequest);

    }

    /** Called when leaving the activity */
    @Override
    public void onPause() 
    {
        if (mAdView != null) 
        {
            mAdView.pause();
        }

        super.onPause();
    }

    /** Called when returning to the activity */
    @Override
    public void onResume() 
    {
        super.onResume();
        if (mAdView != null) 
        {
            mAdView.resume();
        }
    }

    /** Called before the activity is destroyed */
    @Override
    public void onDestroy() {
        if (mAdView != null) 
        {
            mAdView.destroy();
        }
        super.onDestroy();
    }



}

Now im unsure whether it is my code that not generating the device ID or a problem with my created AVD device. The tutorials i seen have something like this

.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
 .addTestDevice("2EAB96D84FE62876379A9C030AA6A0AC") 

Now i don't know if the last line is the code given by LogCat or is something that i just have to put in. I noticed the developer.google website has a different code so i assume i don't need to include in my code since i have not got it yet.

Please help. thank you.

UPDATE 1 I added this code inside On Resume inside my main activity

@Override
    protected void onResume()
    {
        // TODO Auto-generated method stub
        super.onResume();
        int isAvaiable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        if(isAvaiable == ConnectionResult.SUCCESS)
        {
            Log.d("TEST", "GPS IS OK");
        }
        else if(isAvaiable == ConnectionResult.SERVICE_MISSING || isAvaiable == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED || isAvaiable == ConnectionResult.SERVICE_DISABLED)
        {
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvaiable, this, 1);
            dialog.show();
        }

    }
user3364963
  • 397
  • 1
  • 10
  • 28

1 Answers1

1

The API to test banners should be 17 or higher. You have a good answer here that explains it. GPS in emulator.

For the problems related to launch the emulator the only suggestion I can give you is trying VM Acceleration and use an smaller screen. You can try other emulators like x86Emulator and download and the last ISO versions 4.4. In my case the default android emulator took 10-12minutes to be responsive in a ldpi, with the other only 2 in a hdpi.

About the addTestDevice, I think AdRequest.DEVICE_ID_EMULATOR is enough, but if you see in the logcat the MD5 of your device ID then add this hash.

Last but not least, remember to check if GPS are installed at the beginning, it is explained on the DOCS.

To verify the Google Play services version, call isGooglePlayServicesAvailable(). If the result code is SUCCESS, then the Google Play services APK is up-to-date and you can continue to make a connection. If, however, the result code is SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, or SERVICE_DISABLED, then the user needs to install an update.

So you will avoid errors.

Community
  • 1
  • 1
AlexBcn
  • 2,450
  • 2
  • 17
  • 28
  • Hi I made an AVD device exactly like the one on the link you posted Google API 17. The AVD now runs but I am getting another problem. The Ad does not seem to load even though log cat says Ad Finished Loading. When I rotate the ad appears. Another issue that is reported is "Google Play Services are out of date" , "Google Play Services not available due to error 2". I implemented the check that you mentioned about checking the Google play version and posted the code above. The dialog appears saying update services however clicking update seems to cause the dialog to just appear again – user3364963 Oct 03 '14 at 11:36
  • *portrait the ad does not show. Rotate to landscape the ad shows. – user3364963 Oct 03 '14 at 11:37
  • 1
    If your Google Play Services is the last version then try it with the last Google API 19. The Ads can be delayed almost one minute if it is the first run in the device. – AlexBcn Oct 03 '14 at 13:12
  • Thanks, that worked, just took a while like you said. However logcat keeps repeating this error. Come up 6942 times now haha. 10-03 11:31:55.811: E/eglCodecCommon(1247): glUtilsParamSize: unknow param 0x00000bd0 10-03 11:31:55.831: E/eglCodecCommon(1247): **** ERROR unknown type 0x0 (glSizeof,72) – user3364963 Oct 03 '14 at 15:35
  • Looks like it is an error of the [GPU/emulator](http://stackoverflow.com/questions/22348801/phonegap-eclipse-issue-eglcodeccommon-glutilsparamsize-unknow-param-errors), if it is impracticable consider using another emulator. – AlexBcn Oct 04 '14 at 18:10
  • Ah, I did have use host GPU selected on my AVDs haha. Its good to know its not the app then. Thanks for your help – user3364963 Oct 05 '14 at 20:19