【发布时间】:2017-03-13 00:56:41
【问题描述】:
在我尝试将 横幅广告与 AdMob 结合使用后,我的应用程序不断崩溃(没有它一切正常)。 SplashScreen 加载但应用程序在游戏开始时崩溃。以下是我执行此操作的步骤:
1) 我确定我已安装 Google Play 服务 和 Google 存储库
2) 然后我使用 Firebase Tool Assistant 将我的应用程序连接到 Firebase(它只是在 下添加了 google services.json app 文件夹 在我的项目中)
4)我在布局中添加了以下代码:
xmlns:ads="http://schemas.android.com/apk/res-auto"
<com.google.android.gms.ads.AdView
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="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
5)在我的名为“Game”的 Main Activity 类中,我将此代码添加到 onCreate() 方法中,如下所示:
public class Game extends Activity {
//ADMOB
private AdView mAdView;
MediaPlayer sound;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//turn title off
requestWindowFeature(Window.FEATURE_NO_TITLE);
//set to full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(new GamePanel(this));
//ADMOB
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
int[] sounds={R.raw.chiptune, R.raw.chiptune1, R.raw.chiptune2, R.raw.chiptune3};
Random r = new Random();
int Low = 0;
int High = 4;
int rand = r.nextInt(High-Low) + Low;
sound = MediaPlayer.create(getApplicationContext(),sounds[rand]);
sound.start();
sound.setLooping(true);
}
6) 将此添加到我的字符串中:<string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>
7) 在我的 AndroidManifest.xml 中,我添加了以下代码:
<!-- Include required permissions for Google Mobile Ads to run-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!--This meta-data tag is required to use Google Play services.-->
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
如果有人可以提供帮助,我会发现有什么问题!
【问题讨论】:
-
请查看崩溃日志?
-
嗨!我添加了崩溃日志。感谢您的帮助!