0
I am trying to add banner ad in my app by Fragment, but I could not, nothing appears. What can I do to solve?
fragment_inicio.xml
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="324dp"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:visibility="visible"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-xxxxxxxxxxxx~xxxxxxxxxxxx"
ads:layout_constraintTop_toTopOf="parent"
ads:layout_constraintRight_toRightOf="parent"
ads:layout_constraintLeft_toLeftOf="parent"
ads:layout_constraintBottom_toBottomOf="parent"
ads:layout_constraintVertical_bias="1.0">
</com.google.android.gms.ads.AdView>
</androidx.constraintlayout.widget.ConstraintLayout>
Homefragment.java
private AdView mAdView;
public InicioFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_inicio, container, false);
mAdView = view.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
androidManifest
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxx~xxxxxxxxxxxx"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />