Java 安卓:AdMob的问题
我将AdMob添加到我的应用程序中Java 安卓:AdMob的问题,java,android,admob,Java,Android,Admob,我将AdMob添加到我的应用程序中 @Override public void onResume() { super.onResume(); if(adView == null) { // Create the adView adView = new AdView(this, AdSize.BANNER,LabelsShow.AD_UNIT_ID_GOES_HERE); // Lookup your LinearLayo
@Override
public void onResume()
{
super.onResume();
if(adView == null)
{
// Create the adView
adView = new AdView(this, AdSize.BANNER,LabelsShow.AD_UNIT_ID_GOES_HERE);
// Lookup your LinearLayout assuming it’s been given
// the attribute android:id="@+id/mainLayout"
LinearLayout layout = (LinearLayout)findViewById(R.id.l_eadds);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
}
}
xml:
简而言之:安卓4+admob在我的应用程序中起作用。但在安卓2.3中不起作用。
我用4部手机测试了它。两个4+和两个2.3。
在2.3活动中,无横幅(
在其他应用程序中,admob可以工作。我使用不同的策略 在xml中:
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:adSize="BANNER"
app:adUnitId="AD_UNIT_ID_GOES_HERE" >
</com.google.ads.AdView>
希望你能用这个
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:adSize="BANNER"
app:adUnitId="AD_UNIT_ID_GOES_HERE" >
</com.google.ads.AdView>
package com.example.packagename;
import com.google.ads.AdRequest;
import com.google.ads.AdView;
import android.os.Handler;
public class ClassName extends Activity {
private AdRequest re;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final AdView adview = (AdView) findViewById(R.id.adView);
re = new AdRequest();
adview.loadAd(re);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
re = new AdRequest();
adview.loadAd(re);
handler.postDelayed(this, 15000);
}
}, 15000);
--rest of code
}