worldww adlı üyeden alıntı

Siz kodlarınızı paylaşırsanız inceleyelim.


Kullandığım kodlar şu şekilde. Test reklamlarında çalışıyor.


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 interstitialAd = null;

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

interstitialAd= new InterstitialAd(this);
interstitialAd.setAdUnitId("ca-app-pub-20370820*****/*******");
AdRequest adRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(adRequest);

}


@Override
public void onBackPressed() {
if (interstitialAd.isLoaded()) {
interstitialAd.show();
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
super.onAdClosed();
finish();
System.exit(0);
}
});
}else{
super.onBackPressed();
}

}


}







android {
compileSdkVersion 26
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "*****"
useLibrary 'org.apache.http.legacy'
minSdkVersion 15
targetSdkVersion 26
versionCode 2
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})

compile 'com.android.support:appcompat-v7:26.0.0'
compile 'com.google.firebase:firebase-core:11.0.4'
compile 'com.google.firebase:firebase-messaging:11.0.4'
compile 'com.google.android.gms:play-services-ads:11.0.4'
testCompile 'junit:junit:4.12'
}