Admob广告未在真正的android设备上显示
我正在为我的应用程序使用admob广告。我从android studio将默认活动作为admob活动,然后我更改了adunit id。当我在emulator中运行时,它显示了广告,但当我在真实设备中运行相同的代码时,它没有显示任何内容,出现了一个空白屏幕。我正在使用三星J7和三星duos来运行apk。没有任何显示,我寻找了不同的方法,但找不到问题所在。这是我的密码。 这是我的xml文件Admob广告未在真正的android设备上显示,android,admob,ads,live,Android,Admob,Ads,Live,我正在为我的应用程序使用admob广告。我从android studio将默认活动作为admob活动,然后我更改了adunit id。当我在emulator中运行时,它显示了广告,但当我在真实设备中运行相同的代码时,它没有显示任何内容,出现了一个空白屏幕。我正在使用三星J7和三星duos来运行apk。没有任何显示,我寻找了不同的方法,但找不到问题所在。这是我的密码。 这是我的xml文件 <RelativeLayout xmlns:android="http://schemas.androi
<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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<!-- view for AdMob Banner Ad -->
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id"
/>
显示定制现场广告需要更改的内容。问题
您添加了
AdRequest.DEVICE\u ID\u EMULATOR
,因此您可以在EMULATOR中显示AdView(横幅),但并没有添加到实际的设备ID
ca-app-pub-3940256099942544/630978111
是广告单元id不是设备id
解决方案请添加您的真实设备id,请参阅链接。问题
您添加了
AdRequest.DEVICE\u ID\u EMULATOR
,因此您可以在EMULATOR中显示AdView(横幅),但并没有添加到实际的设备ID
ca-app-pub-3940256099942544/630978111
是广告单元id不是设备id
解决方案请添加您的真实设备id,请参阅链接。emulator和真实设备的id不同吗?@UmashankarB yes id两者都不同。请记住为每个应请求测试广告的设备添加测试设备id。设备id由移动ads SDK写入系统日志,因此,您可以通过运行应用程序并检查logcat来查找设备的ID。直播广告(自定义广告)需要哪个ID,我有点困惑。我创建了自己的加载项admob,但我无法在真实设备中显示该广告。显示自己的广告的过程是什么。@UmashankarB您现在在您的真实设备上看到测试广告了吗?emulator和真实设备的Id不同吗?@UmashankarB yes Id两者都不同。请记住为每个应该请求测试广告的设备添加测试设备Id。设备Id由移动ads SDK写入系统日志,因此,您可以通过运行应用程序并检查logcat来查找设备的ID。直播广告(自定义广告)需要哪个ID,我有点困惑。我创建了自己的加载项admob,但我无法在真实设备中显示该广告。显示自己的广告的步骤是什么。@UmashankarB您现在在真实设备上看到测试广告了吗?
public class MainActivity extends AppCompatActivity {
// Remove the below line after defining your own ad unit ID.
private static final String TOAST_TEXT = "Test ads are being shown. "
+ "To show live ads, replace the ad unit ID in res/values/strings.xml with your own ad unit ID.";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Load an ad into the AdMob banner view.
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("ca-app-pub-3940256099942544/6300978111")
.setRequestAgent("android_studio:ad_template").build();
adView.loadAd(adRequest);
// Toasts the test ad message on the screen. Remove this after defining your own ad unit ID.
Toast.makeText(this, TOAST_TEXT, Toast.LENGTH_LONG).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}