2012-07-24 33 views
0

我想在我的測試應用程序中集成admob代碼,這裏是我遵循的步驟。如何將adwhirl代碼集成到android應用程序

佈局文件看起來像這樣

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="bottom" 
     android:id="@+id/layout_ad"> 

</LinearLayout> 

清單文件看起來像這樣

<?xml version="1.0" encoding="utf-8"?> 

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

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 
    <activity 
     android:name=".Dummyads2Activity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

最後這裏的代碼看起來

public class Dummyads2Activity extends Activity {//implements AdWhirlInterface{ 
/** Called when the activity is first created. */ 

private AdWhirlLayout adWhirlLayout; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 


    try{ 
     AdManager.setTestDevices(new String[] { AdManager.TEST_EMULATOR }); 
     LinearLayout layout = (LinearLayout)findViewById(R.id.layout_ad); 
     AdWhirlLayout adWhirlLayout = new AdWhirlLayout(this, "my adwhirl id"); 
     Display d = this.getWindowManager().getDefaultDisplay(); 
     RelativeLayout.LayoutParams adWhirlLayoutParams = new RelativeLayout.LayoutParams(d.getWidth(), 72); 
     layout.addView(adWhirlLayout, adWhirlLayoutParams); 
    }catch(Exception e){ 
     //Log.e(TAG, "Unable to create AdWhirlLayout", e); 
    } 

} 

如果我這樣做,我的應用程序崩潰,並沒有廣告出現。請幫助我解決問題。

+0

如果我錯了,請原諒我的無知,但我沒有理由將其標記爲C++。 – Drise 2012-07-24 15:25:35

回答

0

這真的取決於您使用的AdMob和AdWhirl的版本。我將討論目前最新版本的AdMob SDK v6.1.0和AdWhirl v3.2.0。

你可能會崩潰,因爲這行:

AdManager.setTestDevices(new String[] { AdManager.TEST_EMULATOR }); 

這看起來像舊版的AdMob的AdManager; AdWhirl使用Google AdMob SDK。無論如何,如果您想通過AdWhirl來測試廣告,您希望通過AdWhirl進行測試,而不是通過廣告網絡進行測試。因此,除去上面一行,並設置測試模式是這樣的:

AdWhirlTargeting.setTestMode(true); 

而且,你的清單將需要擁有所有權限,並且正在與中介網絡的活動定義的超集。對於AdMob,您需要添加:

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

如果您仍然遇到錯誤,發佈一些日誌輸出將會很有用。如果你使用的是Eclipse,你可以在Window - > Show View - > Other ... - > Android - > LogCat中找到logcat。或者,您可以使用adb logcat和Android的adb工具從命令行獲取logcat輸出。

相關問題