Reputation: 64
I have a problem with Admob in android app. Every time on logcat am getting the dialogue ad is not visible, Not refreshing ad. Error Code 2 and Scheduling ad refresh 60000 milliseconds from now.
Testing on Xiaomi Redmi note 2
in main activity.xml I have that code
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
I added to AndroidManifest.xml
and
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
and
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
Java code
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 MainMenuActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators
.addTestDevice("F362E9BD751EF0E1933B8FEEDDD2A0BD") // An example device ID
.build();
mAdView.loadAd(request);
}
}
What's more in build gradle I have compile 'com.google.android.gms:play-services-ads:8.4.0'
So what can be wrong?
Upvotes: 0
Views: 364
Reputation:
Have you added following code in
@Override
protected void onPause() {
mAdView.pause();
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
mAdView.resume();
}
Disable your Ad blocker. Make sure you don't have an app like adBlock installed.
Anyway, that error means "Timed out waiting for ad response", so check your Internet connection and try changing from Wi-Fi to Mobile Network
Update
in main activity.xml I have that code
Are you sure you have added AdView
in activity_main_menu.xml
layout not activity.xml
because in your code your activity's layout is activity_main_menu. BTW layout name suggest that it is a layout for activity's menu not activity itself.
setContentView(R.layout.activity_main_menu);
Upvotes: 1