[英]Admob ad not showing on adview
我正在嘗試對我的應用進行adview。 我在xml上添加了一個adview,如下
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp" >
<ScrollView
android:id="@+id/ScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<!-- Name Label -->
<TextView
android:id="@+id/name_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dip"
android:paddingTop="10dip"
android:textSize="15sp"
android:textStyle="bold" />
</ScrollView>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/ScrollView1"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-6045707126584551/3116181621"
android:layout_alignParentBottom="true" >
</com.google.android.gms.ads.AdView>
</RelativeLayout>
這是我為了在Java中初始化adview而實現的代碼。 該代碼應加載廣告。
public class SingleContactActivity extends Activity {
// JSON node keys
static final String ID = "id";
static final String POS = "position";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_contact);
// getting intent data
Intent in = getIntent();
// Get JSON values from previous intent
String name = in.getStringExtra(ID);
// Displaying all values on the screen
TextView lblName = (TextView) findViewById(R.id.name_label);
lblName.setText(name);
// Look up the AdView as a resource and load a request.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("479004f857d93000").build();
adView.loadAd(adRequest);
}
}
當我嘗試廣告時,該廣告未加載到設備上。 任何提示或幫助將不勝枚舉。 謝謝。
哦,我找到了解決方案。 這是我第一次使用adview,因此有些困惑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.