简体   繁体   English

android 应用程序中的广告无法正常工作

[英]Ads in android app not working correctly

I am making an Android app within which I wish to display ads, however I can't get it to work correctly.我正在制作一个 Android 应用程序,我希望在其中显示广告,但我无法使其正常工作。

When I try to add the configChanges to the AndroidManifest.xml , I get the following error, which is likely to be the problem...当我尝试将configChanges添加到AndroidManifest.xml时,出现以下错误,这很可能是问题所在...

error: Error: String types not allowed (at 'configChanges' with value 'keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize').

This is my AndroidManifest.xml file...这是我的 AndroidManifest.xml 文件...

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

<uses-sdk android:minSdkVersion="3" />
<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:label="@string/app_name"
        android:name=".ParachutehunterActivity" android:screenOrientation="portrait" android:configChanges="orientation">

        <intent-filter >
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:label="@string/app_name" android:name=".GameScreenActivity" android:screenOrientation="portrait" android:configChanges="orientation"></activity>
    <activity android:name=".playerLostMessageActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:configChanges="orientation"></activity>
    <activity android:name="com.mysoftwaremobileapps.ParachuteHunterLite.SubmitScoreActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:configChanges="orientation"></activity>
    <activity android:configChanges="keyboard|keyboardHidden|orientation" android:label="@string/app_name" android:name=".AdActivity" android:screenOrientation="portrait"></activity>
    <activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>


</application>

</manifest>

And this is my Activity that i'm using to add the ads to my app...这是我用来将广告添加到我的应用程序的活动...

package com.mysoftwaremobileapps.ParachuteHunterLite;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

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

public class AdActivity extends Activity implements OnClickListener{
//Called when the activity is first created
Button AdsButton;
public String value;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.adscreen);
    AdsButton = (Button)findViewById(R.id.AdsButton);
    AdsButton.setOnClickListener(this);
    AdView myAdView = new AdView(this, AdSize.BANNER, "Your Publish ID");

    //get layoutView
    LinearLayout rootView = (LinearLayout)this.findViewById(R.id.MainLayout3);
    LinearLayout.LayoutParams layoutParams = new LayoutParams(320, 50);
    rootView.addView(myAdView, 0, layoutParams);        

    AdRequest re = new AdRequest();
    re.setGender(AdRequest.Gender.UNKNOWN);
    //re.setTestDevices(testDevices);
    //re.setTesting(testing)
    myAdView.loadAd(re);
}
public void onClick(View src) {
    switch(src.getId()) {
    case R.id.AdsButton:
        Uri ParachuteHunterPurchaseSite = Uri.parse("https://play.google.com/store/apps/details?id=com.mysoftwaremobileapps.ParachuteHunter&feature=search_result#?t=W251bGwsMSwyLDEsImNvbS5teXNvZnR3YXJlbW9iaWxlYXBwcy5QYXJhY2h1dGVIdW50ZXIiXQ..");
        Intent launchParachuteHunterPurchaseSite = new Intent(Intent.ACTION_VIEW, ParachuteHunterPurchaseSite);
        startActivity(launchParachuteHunterPurchaseSite);
        break; 
    }
}
}

Please note that the onClick(AdsButton) method in the Activity is not related to the AdView provided by Google.请注意, Activity中的onClick(AdsButton)方法与 Google 提供的AdView无关。

For the android:configChanges error, is it complaining because your application has a minSdkVerion="3" but some of the values in your configChanges line do not exist until SDK 13, such as screenSize|smallestScreenSize .对于android:configChanges错误,它是否在抱怨,因为您的应用程序具有minSdkVerion="3"但您的configChanges行中的某些值直到 SDK 13 才存在,例如screenSize|smallestScreenSize

Refer to http://developer.android.com/reference/android/R.attr.html#configChanges which says that These values must be kept in sync with those in ActivityInfo and include/utils/ResourceTypes.h请参阅http://developer.android.com/reference/android/R.attr.html#configChanges这些值必须与 ActivityInfo 和 include/utils/ResourceTypes.h 中的值保持同步

If this doesn't solve the problem, could you please tell us what exactly isn't working .如果这不能解决问题,请告诉我们到底是什么不起作用 For example, are you getting any Exceptions or errors?例如,您是否收到任何异常或错误?

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

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