2017-08-11 64 views
0

嗨,大家好,我將admob橫幅廣告集成到了我的主要活動中,並且工作得很好,但是當我嘗試添加admob插頁式廣告時,會導致應用在打開時崩潰建設APK 什麼AMI做錯了Android工作室 - Admob插頁式廣告集成導致應用崩潰

我只是個初學者在Java編碼所以我不會那麼多熟悉的envirement 的朋友有所幫助時,顯示沒有錯誤了

package this.atest.packagename.myapplication; 

import android.content.ActivityNotFoundException; 
import android.content.Intent; 
import android.net.Uri; 
import android.sax.StartElementListener; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 

import com.google.android.gms.ads.AdListener; 
import com.google.android.gms.ads.AdRequest; 
import com.google.android.gms.ads.AdView; 
import com.google.android.gms.ads.InterstitialAd; 

public class MainActivity extends AppCompatActivity { 

    InterstitialAd mInterstitialAd; 
    private InterstitialAd interstitial; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 




     AdRequest adRequest1 = new AdRequest.Builder().build(); 

     // Prepare the Interstitial Ad 
     interstitial = new InterstitialAd(MainActivity.this); 
// Insert the Ad Unit ID 
     interstitial.setAdUnitId(getString(R.string.interstitial)); 

     interstitial.loadAd(adRequest1); 
// Prepare an Interstitial Ad Listener 
     interstitial.setAdListener(new AdListener() { 
      public void onAdLoaded() { 
// Call displayInterstitial() function 
       displayInterstitial(); 
      } 
     }); 
     Button btn1 =(Button)findViewById(R.id.btn1); 

     btn1.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent intent = new Intent(MainActivity.this, Main2Activity.class); 
       startActivity(intent); 

      } 
     }); 



     AdView adView = (AdView) findViewById(R.id.adViewBanner); 
     AdRequest adRequest = new AdRequest.Builder() 
       .setRequestAgent("android_studio:ad_template").build(); 
     adView.loadAd(adRequest); 



    } 


    public void displayInterstitial() { 
// If Ads are loaded, show Interstitial else show nothing. 
     if (interstitial.isLoaded()) { 
      interstitial.show(); 
     } 
    } 

} 
+0

您可以發佈您的崩潰日誌(同時過濾adb日誌以顯示「廣告」)。 –

回答

0

有你加入這個你的Manifest?

<activity 
android:name="com.google.android.gms.ads.AdActivity" 
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" 
      android:theme="@android:style/Theme.Translucent" /> 
0

你只要看看在你的XML文件應該是

xmlns:ads="http://schemas.android.com/apk/res-auto" 

而且

ads:loadAdOnCreate="true" 
0

你一定要試試這個

interstitial.setAdUnitId(getResources().getString(R.string.intertitial)); 

有時GetString的不取這樣這很有幫助。