2012-09-01 60 views
0

我制作了一个应用程序,之前使用过adMob广告,但由于某种原因,它不适用于我的最新应用程序。该应用程序工作正常,直到我把我的XML编码。Admob xml错误

我添加外部JAR:

我添加的代码清单:

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="14" /> 

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 
    <meta-data 
     android:name="ADMOB_PUBLISHER_ID" 
     android:value="a1504053602839f" /> 

    <activity 
     android:name="com.google.ads.AdActivity" 
     android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" /> 

我改变了我的目标在的.properties -14:

我还添加了这个代码到我的xml布局的顶部:

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 

这是我用于实际广告的代码:

<com.google.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     ads:adSize="BANNER" 
     ads:adUnitId="a150072b02930f" 
     ads:loadAdOnCreate="true" /> 

就像我说的,我有一个月前与我的其他应用程序工作的确切代码。

当我在我的xml中粘贴我的ads.AdView代码时,应用程序甚至不会启动。一旦我将代码剪出来,应用程序运行良好,没有广告。 此外,我的Startup类中只有Game类没有广告。但是一旦我启动应用程序,它就会崩溃。

有什么建议吗?

+0

有什么日志?你需要什么元数据应答器?该工作没有 – damson

+0

崩溃的日志会有所帮助。我的猜测是,您没有正确关联AdMob库 - 您可能在外部引用了它,但没有导出它。确保将库放置在应用程序的库/文件夹中。此外,它看起来像XML中的adUnitId长度只有14个字符 - 它应该可能是15.这并不能解释崩溃,但是一旦你使用它,你就不会看到广告,如果这个adUnitId其实是不正确的。 –

回答

0

我没有使用元数据为了从admob获得添加,所以我不能告诉你,如果错误驻留在元数据,其他明智的代码是完美的。

你可以检查你添加的jar,可能是腐败或不知道。您可以使用此代码,可以检查它是否在您的应用程序

<activity 
     android:name="com.google.ads.AdActivity" 
     android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" 
     android:launchMode="singleTop" 
     android:screenOrientation="portrait" 
     android:theme="@android:style/Theme.NoTitleBar.Fullscreen" /> 
    <!-- Track Market installs from AdMob ads --> 
    <receiver 
     android:name="com.google.ads.InstallReceiver" 
     android:exported="true" > 
     <intent-filter> 
      <action android:name="com.android.vending.INSTALL_REFERRER" /> 
     </intent-filter> 
    </receiver> 

奠定了工作 -

<TableRow 
    android:id="@+id/tbl" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="63dp" 
    android:gravity="center" > 

    <com.google.ads.AdView 
     android:id="@+id/adddd" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     ads:adSize="BANNER" 
     ads:adUnitId="a14fe2bc0ebbc0c" 
     ads:backgroundColor="#FFFF00" 
     ads:keywords="SNS" 
     ads:loadAdOnCreate="true" 
     ads:primaryTextColor="#FFFFFF" 
     ads:refreshInterval="30" 
     ads:secondaryTextColor="#CCCCCC" 
     android:visibility="visible" /> 
</TableRow>