0

I followed the instructions here, I'm compiling my app in the 14 API, I already setup a publisher ID, and everything is fine, except for: I can't test the ads on my app because I can't find that "adRequest" filtered to find my device ID, and because testing on an emulator does not work as well. And, to make things worse: I don't know, exactly, how to call the ad activity on my app activity. Here we go:

I've created a class called "Money":

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;

/**
 * Created by EricsonWillians on 07/03/14.
 */
public class Money extends Activity {

    private AdView adView;
    private static final String AD_UNIT_ID = "My Publisher ID 9348923432342";

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        adView = new AdView(this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(AD_UNIT_ID);

        LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
        layout.addView(adView);

        AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
                .build(); // Can't find the bloody "hashed device ID" even filtering the whole logcat (I'm using IntelliJ IDEA).

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

    @Override
    public void onResume() {
        super.onResume();
        if (adView != null) {
            adView.resume();
        }
    }

    @Override
    public void onPause() {
        if (adView != null) {
            adView.pause();
        }
        super.onPause();
    }

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

And, to make things worse again, I've changed the code to try to use the emulator:

AdRequest adRequest = new AdRequest.Builder().build();
adRequest.addTestDevices(AdRequest.TEST_EMULATOR); // Does not work.

And I get from the IDE that the "addTestDevices" method and the AdRequest.TEST_EMULATOR cannot be resolved.

How can I get my device ID on that logcat, and how can I call this ad activity in my app activity?

sergej shafarenka
  • 20,071
  • 7
  • 67
  • 86
Ericson Willians
  • 7,606
  • 11
  • 63
  • 114

1 Answers1

3

You should find a line like this in your LogCat:

03-06 23:11:17.885: I/Ads(3919): Use AdRequest.Builder.addTestDevice("XXXXXXXXXXXXXXXXX") to get test ads on this device.

03-06 23:11:17.920: I/Ads(3919): Starting ad request.

If you can't see this, I think this way you can get the ID of your device so try to set it manually.

String android_id = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
String deviceId = md5(android_id).toUpperCase();
nKn
  • 13,691
  • 9
  • 45
  • 62
  • All this assuming you're setting the right value for `AD_UNIT_ID`, as `My Publisher ID 9348923432342` is not a valid value. – nKn Mar 07 '14 at 09:53
  • I'm setting the right value in the original file. I could not find the message on logcat, so I tried your method, and "md5" could not be resolved (The IDE does not find it, and its color is red). – Ericson Willians Mar 07 '14 at 10:03
  • Use can use this example to implement a `md5()` method: http://stackoverflow.com/questions/3934331/android-how-to-encrypt-a-string – nKn Mar 07 '14 at 10:53