My adMOB test app compile without problems (apk is created), but when
I try run it in my Samsung cellphone (SM-G531BT - Android 5.1.1)
nothing is displayed, only the message: "The adMobTeste stopped." (an
AlertDialog).
I used try...catch but it not display nothing.
In MainActivity.java:
package net.testes.admobteste;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
AlertDialog msg;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
try {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdView propaganda = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("xxE1Axx75481630A10256ED92AF3xxxx")
.build();
propaganda.loadAd(adRequest);
} catch (Exception e) {
//e.printStackTrace();
//e.getMessage();
builder.setTitle("Erro");
builder.setMessage(e.getMessage());
msg = builder.create();
//Exibe
msg.show();
}
}
}
In strings.xml:
<resources>
<string name="app_name">AdMobTeste</string>
<string name="banner_ad_unit_id">ca-app-
pub-3940256099942544/6300978111</string>
</resources>
In activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:visibility="visible"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
I'm testing banner use in android apps. Someone code doesn't display
here (xml and html).