0

I want to display Google ads on the user's location (user's country). For example, users in Iran will receive Persian advertisements and ... I also do not want to get a location permission from the user.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    AdRequest adRequest = new AdRequest.Builder()
            .build();

    mAdView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
        }

        @Override
        public void onAdClosed() {
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
        }

        @Override
        public void onAdLeftApplication() {
        }

        @Override
        public void onAdOpened() {
            super.onAdOpened();
        }
    });

    mAdView.loadAd(adRequest);

}

and XML layout for Google-Ads Banner type:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.ads.AdView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    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:layout_gravity="bottom|center_horizontal"
    android:layout_margin="5dp"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_home_footer" />
MkDev
  • 21
  • 1
  • 5
  • Possible duplicate of [How to request Location Permission at runtime on Android 6](https://stackoverflow.com/questions/40142331/how-to-request-location-permission-at-runtime-on-android-6) – Eselfar Jun 21 '18 at 16:34
  • @Eselfar No, this is not my answer – MkDev Jun 21 '18 at 17:06

0 Answers0