2

Possible Duplicate:
How can I get device ID for Admob

My activity has a ListView and I've put an ad at the bottom. When I run the app on the emulator, I see the test ad. When I run on my phone, I get an actual ad. I want to test on my phone and not get real ads.

I followed the instructions on the AdMob site about looking in logcat for a message stating how to manually add the device ID to the AdRequest. The problem is this message would never appear in logcat. This is a RAZR running 4.1. In an SO post, answered by Aracem, I read that the encoded string is available in the Developer Options preference panel, and I found it. When I read the guide for this command, the format of the device ID was alphanumeric (e.g. "E83D20734F72FB3108F104ABC0FFC738"), but the value in my phone contains letters, numbers, and dashes (e.g. "MQKF-RB61-BBKS-E").

I've added the encoded device ID into the XML googleads:testDevices and I've also manually added an AdRequest into my onCreate and use addTestDevice with this string. Neither work.

One thing that I've noticed is the namespace that works is googleads, not ads as shown in the examples. When I use ads, I get prefix errors in the XML. I'm guessing with the switch from 4.x to 6.1, the namespace changed.

I can make this happen with the minimal project where onCreate does nothing more than call super and setContentView.

Layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
    android:id="@+id/list"
    android:layout_above="@+id/adView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
<com.google.ads.AdView
    xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@id/adView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    googleads:adSize="BANNER"
    googleads:adUnitId="@string/admob_id"
    googleads:loadAdOnCreate="true"
    googleads:testDevices="TEST_EMULATOR, MQKF-RB61-BBKS-E" />

Manifest

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="16" />
<application android:label="@string/app_name" >
    <activity
        android:name="mainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>
Community
  • 1
  • 1
Eric Cloninger
  • 2,260
  • 2
  • 21
  • 26

1 Answers1

8

In the Logcat, you will find the device ID. You will see something like

To get test ads on this device, call adRequest.addTestDevice("**")

user1550193
  • 106
  • 3
  • 1
    As I said above, that message does not appear in the logcat output. I suspect this is a change in the procedure for JellyBean. – Eric Cloninger Jul 29 '12 at 17:11
  • I do not have googleads:loadAdOnCreate="true" and googleads:testDevices="TEST_EMULATOR, MQKF-RB61-BBKS-E" and it works and displays in logcat about the addTestDevice. – user1550193 Jul 30 '12 at 13:34
  • That isn't working. Just tried it. Thanks, though. I had to manually create the adRequest from onCreate, but that message didn't appear. I get the notice that the ad was clicked, just not this message with the hashed device ID. – Eric Cloninger Jul 30 '12 at 22:38
  • 6
    Aha! I figured it out. If you **already have** "ads:testDevices=" in your layout XML file, AdMob will NOT print the "to get test ads on this device..." message in the logcat output. Take that out, and then you will see the logcat message. – Andy Dennie Dec 13 '12 at 16:42
  • Also ensure your log filtering is set for "verbose" otherwise you won't see the required output (at least in Eclipse, anyway). – Shanker Kaura Jun 15 '14 at 03:14