Android: AdMob not working(Android:AdMob 无法正常工作)
问题描述
AdMob 不会显示在我的应用中.每次我调用 loadAd(..)
我都会收到以下错误:
AdMob won't show in my app. Every time I invoke loadAd(..)
I get the following errors:
请求资源 0x7f0b000e 失败,因为它很复杂.谷歌未找到播放服务资源.检查您的项目配置以确保包含资源.获得广告响应时出现问题.错误代码:1
Requesting resource 0x7f0b000e failed because it is complex. The Google Play services resources were not found. Check your project configuration to ensure that the resources are included. There was a problem getting an ad response. ErrorCode: 1
我搜索了几个小时来解决这个问题,但没有找到任何适合我的方法!我下载了最新版本的 Google Play Services
并将它们作为库添加到我的项目首选项中
I searched hours for a solution to this problem but haven't found anything that works for me! I downloaded the latest version of the Google Play Services
and added them as library in my project preferences
这是我的代码:活动:
public class WelcomeActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_welcome);
// Look up the AdView as a resource and load a request.
AdView adView = (AdView) this.findViewById(R.id.welcomeAdView);
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
adRequestBuilder.addTestDevice("************");
adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
AdRequest adRequest = adRequestBuilder.build();
adView.loadAd(adRequest);
}
}
布局xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res/xx.xx"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="xx.xx.WelcomeActivity" >
.... other layout stuff .....
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true" >
<com.google.android.gms.ads.AdView
android:id="@+id/welcomeAdView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="pub-***************" />
</RelativeLayout>
</RelativeLayout>
AndroidManifest.xml:
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xx.xx"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Light" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="xx.xx.WelcomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
... some more activities ...
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" >
</activity>
</application>
</manifest>
推荐答案
我没有发现您的代码/布局有任何问题.广告单元 ID
可能存在问题.
I don't find any issue with your code/layout. Issue could be with the Ads Unit Id
.
我建议您尝试创建一个不同的广告单元 ID
I would suggest you to try creating a different Ads Unit Id
希望它有效.
这篇关于Android:AdMob 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android:AdMob 无法正常工作
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01