当我用自己的帐户(admob)替换广告单元和应用ID时,我的应用中未显示的Admob广告
我同时尝试了构建版本和单一版本的apk,没有显示任何广告,我的admob帐户显示有广告请求,但没有显示印象。
请帮助我,如何处理此问题?我是新开发人员。
主电:-
public class MainActivity extends AppCompatActivity {
Button B1, B2;
AdView madView;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
madView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
madView.loadAd(adRequest);
/**B1 to A1*/
B1 = (Button) findViewById(R.id.B1);
B1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent n1 = new Intent(MainActivity.this, Activity1.class);
startActivity(n1);
}
});
/**B2 to A2*/
B2 = (Button) findViewById(R.id.B2);
B2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent n2 = new Intent(MainActivity.this, Activity2.class);
startActivity(n2);
}
});
}
}
<ScrollView
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="600dp"
android:background="@color/colorPrimaryDark"
android:orientation="vertical"
tools:ignore="ExtraText">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="600dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/B1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="@color/colorAqua"
android:gravity="center"
android:padding="10dp"
android:textAlignment="center"
android:textColor="@color/colorvoilet"
android:textSize="17sp"
android:textStyle="bold"
android:text="@string/q1"/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/B2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="@color/colorAqua"
android:padding="10dp"
android:textColor="@color/colorvoilet"
android:textAlignment="center"
android:gravity="center"
android:textSize="17sp"
android:textStyle="bold"
android:text="@string/q2"/>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
<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"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>`enter code here`
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity android:name=".Activity1">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
</application>
</manifest>
答案 0 :(得分:0)
将代码添加到清单文件:-
<manifest>
<application>
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="YOUR_ADMOB_APP_ID"/>
</application>
和java文件中的addTestDevice:
AdRequest request = new AdRequest.Builder()
.addTestDevice("33BE2250B43518CCDA7DE426D04EE231") // add your decide ID shown in logcat
.build();