繁体   English   中英

如何在我们的Android应用程序中添加

[英]how to Put add in our android application

我已经为admob创建了一个应用程序,但是我收到了一个错误。 我找到了谷歌的一个例子,我已经尝试过,但是当我启动应用程序时出现问题。

我正在使用Android 2.2 API 8.我能够启动应用程序,但此块导致错误。

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

如果我改成这个

android:configChanges="keyboard|keyboardHidden"

然后我就可以启动应用程序,但是我们的添加字段会出现错误。

you must have adactivity declare in Android Manfiest.xml with config change

由于这个原因,我无法在我们的应用程序中显示谷歌添加。

请帮我解决这个问题。

我想你只需要遵循这个教程。

特别是你的问题应该是这样的:

适用于Android的Google AdMob Ads SDK需要Android 1.5或更高版本。 确保您拥有Android SDK的最新副本,并且您正在编译至少Android v3.2(将default.properties中的目标设置为android-13)。

这意味着minSDK可以降至1.5但你必须至少在3.2上编译。

来自AdMob文档

您需要将整个活动标记添加到AndroidManifest.xml

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

请参阅https://developers.google.com/mobile-ads-sdk/docs/android/fundamentals

 - AdActivity.java

package com.android.ads;

import android.app.Activity;
import android.os.Bundle;

import com.google.ads.AdRequest;
import com.google.ads.AdView;

public class AdsActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        AdView adview = (AdView) findViewById(R.id.adView);
        AdRequest re = new AdRequest();
        re.setTesting(true);
        re.setGender(AdRequest.Gender.FEMALE);
        adview.loadAd(re);
    }
}

 - main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

        xmlns:ads="http://schemas.android.com/apk/res/com.android.ads"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

     <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="Your adunit ID" 
        android:layout_alignParentBottom="true"/>    
</LinearLayout>

Remember Put GoogleMapAdmobSdk.jar after creating libs folder for Configure build path 


Create the attrs.xml in the Values folder

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <declare-styleable name="com.google.ads.AdView">
      <attr name="adSize">
          <enum name="BANNER" value="1"/>
          <enum name="IAB_MRECT" value="2"/>
          <enum name="IAB_BANNER" value="3"/>
          <enum name="IAB_LEADERBOARD" value="4"/>
      </attr>
      <attr name="adUnitId" format="string"/>
  </declare-styleable>
</resources>

 - AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.ads"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />
 <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".AdsActivity"
            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"/>
    </application>

</manifest>


Your work is done buddy............

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM