2012-04-10 24 views
0

我正在製作Android應用,我希望在其中展示廣告,但無法使其正常工作。Android應用中的廣告無法正常工作

當我嘗試了configChanges添加到AndroidManifest.xml,我碰到下面的錯誤,這很可能是問題...

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

這是我的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> 

這是我的活動,我使用的廣告添加到我的應用程序...

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; 
    } 
} 
} 

請注意,Activity中的onClick(AdsButton)方法與Google提供的AdView無關。

+0

請參閱答案http://stackoverflow.com/questions/7902121/admob-cant-display-ads-because-of-configchanges – Tomik 2012-04-10 14:24:59

回答

0

對於android:configChanges錯誤,是不是在抱怨,因爲您的應用程序有一個minSdkVerion="3"但一些在你configChanges線的值不存在,直到SDK 13,如screenSize|smallestScreenSize

參考http://developer.android.com/reference/android/R.attr.html#configChanges它說,這些值必須保持與那些ActivityInfo同步和包括/ utils的/ ResourceTypes.h

如果不解決這個問題,你可以請告訴我們什麼正好不工作。例如,你是否收到任何異常或錯誤?

+0

問題不是minSdkVersion(它必須至少是3級),但是建立目標(至少需要編譯Android 3.2)。 – Tomik 2012-04-10 14:29:01

+0

謝謝,這看起來更合乎邏輯,我沒有拿起它,因爲它沒有在問題提供的AndroidManifest.xml中指定:-) – wattostudios 2012-04-10 14:36:04

+0

非常感謝!沒有更多的錯誤,但沒有廣告出現?我跑到我的手機上的應用程序3次魔杖每次等待3分鐘。僅僅是因爲這個時刻/情況沒有任何廣告可用,或者我做錯了什麼?我還沒有添加我的發佈者ID。 – user1183066 2012-04-10 18:51:58

相關問題