[英]Admob ads is not displaying
Pls help me... I just finished my first android app and wanted to include admob ads but the ads are not showing请帮帮我...我刚刚完成了我的第一个 android 应用程序并想包含 admob 广告,但广告没有显示
How can i solve this problem?我怎么解决这个问题? I also used the test ads but that one doesnt display also我也使用了测试广告,但也没有显示
My MainActivity code我的 MainActivity 代码
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private AdView mAdView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_main);
setSupportActionBar(toolbar);
Fragment fr = new CoursesFragment();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.content_frame, fr);
ft.commit();
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
..... ......
}
My Courses Fragment.我的课程片段。 I used banner ads here我在这里使用了横幅广告
private AdView mAdView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
final View rootView = inflater.inflate(R.layout.fragment_courses, container, false);
....
mAdView = rootView.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
return rootView;
}
} }
My Question Activity.我的问题活动。 I used interstitial ads here我在这里使用了插页式广告
private Context context;
private InterstitialAd mInterstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_question);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_question);
setSupportActionBar(toolbar);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-pub-2005641929118957/8785xxxx");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
ActionBar action = getSupportActionBar();
action.setDisplayHomeAsUpEnabled(true);
context = this;
ListView list = (ListView)findViewById(R.id.list_level3qq);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
....
}
} }
My fragment layout我的片段布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".CoursesFragment">
......
<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"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-200564192911895/1290xxxxx">
</com.google.android.gms.ads.AdView>
My Android Manifest file includes the below我的 Android 清单文件包括以下内容
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-2005641929118957~2331645520" /> <
i have also imported and added the google play services into my sdk我还将谷歌播放服务导入并添加到我的 sdk
The error message i get from my logcat concerning the ads我从 logcat 收到的关于广告的错误消息
E/Flurry: Ad server responded with the following error(s):
02-25 18:27:19.944 2756-24973/? E/Flurry: Adunit is not active
? E/AsyncOperation: operation=xlb, opStatusCode=12009 [CONTEXT service_id=45 ]
OperationException[Status{statusCode=unknown status code: 12009, resolution=null}]
at atnm.g(:com.google.android.gms@210214017@21.02.14 (040306-352619232):1)
at atnm.fW(:com.google.android.gms@210214017@21.02.14 (040306-352619232):29)
at abcx.run(:com.google.android.gms@210214017@21.02.14 (040306-352619232):9)
at bqlt.run(:com.google.android.gms@210214017@21.02.14 (040306-352619232):2)
at tmw.c(:com.google.android.gms@210214017@21.02.14 (040306-352619232):6)
at tmw.run(:com.google.android.gms@210214017@21.02.14 (040306-352619232):7)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at tsu.run(:com.google.android.gms@210214017@21.02.14 (040306-352619232):0)
at java.lang.Thread.run(Thread.java:818)
invalid stream - problem with parameter iterator in /data/data/com.google.android.gms/app_chimera/m/00000008/AdsDynamite.apk for method void com.google.android.gms.ads.nonagon.ad.event.p.a(java.lang.Object)
to Test your ads you can't use your live ad id you should instead use testing id要测试您的广告,您不能使用您的实时广告 ID,您应该使用测试 ID
interstitial test id : ca-app-pub-3940256099942544/1033173712
banner test id: ca-app-pub-3940256099942544/6300978111
replace your ids with these test ids to be able to see your ads in testing mode用这些测试 ID 替换您的 ID,以便能够在测试模式下看到您的广告
from your code everything looks good the implementation seems correct but you are not able to see the ad since its a live ad not a test ad.从您的代码来看,一切看起来都不错,实施似乎是正确的,但您无法看到广告,因为它是实时广告而不是测试广告。
You can start with this quick-start您可以从这个快速入门开始
Make sure you include this in the manifest file确保将其包含在清单文件中
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
Test AdMob app ID: ca-app-pub-3940256099942544~3347511713测试AdMob app ID:ca-app-pub-3940256099942544~3347511713
The source for the Test Admob app ID测试源 Admob app ID
Also you can find here the Testing ids您也可以在这里找到测试 ID
App Open: ca-app-pub-3940256099942544/3419835294应用打开:ca-app-pub-3940256099942544/3419835294
Banner: ca-app-pub-3940256099942544/6300978111横幅:ca-app-pub-3940256099942544/6300978111
Interstitial: ca-app-pub-3940256099942544/1033173712插页式广告:ca-app-pub-3940256099942544/1033173712
Interstitial Video: ca-app-pub-3940256099942544/8691691433插页式视频:ca-app-pub-3940256099942544/8691691433
Rewarded: ca-app-pub-3940256099942544/5224354917奖励:ca-app-pub-3940256099942544/5224354917
Rewarded Interstitial: ca-app-pub-3940256099942544/5354046379奖励插页式广告:ca-app-pub-3940256099942544/5354046379
Native Advanced: ca-app-pub-3940256099942544/2247696110本机高级:ca-app-pub-3940256099942544/2247696110
Native Advanced Video: ca-app-pub-3940256099942544/1044960115本机高级视频:ca-app-pub-3940256099942544/1044960115
replace your ids with these test ids to be able to see your ads in testing mode用这些测试 ID 替换您的 ID,以便能够在测试模式下看到您的广告
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.