Admob banner主なアクティビティ:広告とバナーはありません。私は複数のスマートフォンで試してみました。しかし、main.xmlのデザインプレビューの広告バナーが表示されます。Admobはアンドロイドスタジオ2.0で動作しません
ここに私のコードです:
build.gradleMain.java
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class `MainActivity` extends Activity
Button sharebutton;
public MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
文字列
string name="banner_ad_unit_id">ca-app-pub-5281300412510582/8914765755</string>
apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "24.0.0 rc3" defaultConfig { applicationId "com.example.app" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.3.0' compile 'com.android.support:design:23.3.0' compile 'com.google.android.gms:play-services-ads:8.4.0' }
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/x">
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/banner_ad_unit_id"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
</com.google.android.gms.ads.AdView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/onww"
android:id="@+id/warnone"
android:background="#69f830"
android:layout_above="@+id/warntwo"
android:layout_alignLeft="@+id/warntwo"
android:layout_alignStart="@+id/warntwo"
android:layout_marginBottom="35dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/twow"
android:id="@+id/warntwo"
android:background="#fec357"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/threew"
android:id="@+id/warnthree"
android:layout_marginTop="31dp"
android:layout_below="@+id/warntwo"
android:layout_centerHorizontal="true"
android:background="#ff0000" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/stop"
android:id="@+id/stop"
android:layout_below="@+id/warnthree"
android:layout_centerHorizontal="true"
android:layout_marginTop="42dp"
android:background="#000000"
android:textColor="#ffffff" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/whrmymoney"
android:background="@drawable/moneycash"
android:layout_above="@+id/warnone"
android:layout_centerHorizontal="true"
android:layout_marginBottom="54dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/share"
android:id="@+id/share1"
android:layout_alignTop="@+id/warnone"
android:layout_alignLeft="@+id/adView"
android:layout_alignStart="@+id/adView" />
</RelativeLayout>
マニフェスト
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx.xxxxx">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".x"
android:label="@string/title_activity_x_xxvby"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
</application>
</manifest>
あなたのIDとと[email protected]を変更してください解決策を与えている、それを確認してください。 – Lampard
アンドロイドスタジオ2.0では問題ありません。あなたのadmobバナーIDをデフォルトまたは新しいものに変更してみてください。try.iは同じ問題をフェッチしますが、これを解決するには新しいIDを試してください。 –
問題は持続し、新しい広告IDを試してみて、diffアプリでテストしたところ、モバイルデータでしかテストされていません.WiFiはまだテストされていません。 – Robzorc