Ad admob ads

This commit is contained in:
Billy Brawner 2019-02-10 13:12:51 -06:00 committed by William Brawner
parent 004d3c94ca
commit 45f1c54eb1
7 changed files with 64 additions and 8 deletions

View file

@ -1,7 +1,7 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
buildToolsVersion '28.0.2'
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 14

View file

@ -44,10 +44,14 @@ android {
}
}
buildTypes {
debug {
resValue "string", "adbmob_ad_unit_id", "ca-app-pub-3940256099942544/6300978111"
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
resValue "string", "adbmob_ad_unit_id", "ca-app-pub-3319579963502409/4464724664"
}
}
flavorDimensions "platform"
@ -98,5 +102,10 @@ dependencies {
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.6'
implementation "ch.acra:acra-http:$acraVersion"
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-ads:17.1.3'
implementation 'com.android.billingclient:billing:1.2'
samsungImplementation project(":IAP5Helper")
}
apply plugin: 'com.google.gms.google-services'

View file

@ -17,6 +17,10 @@
android:theme="@style/AppTheme"
tools:ignore="AllowBackup"
tools:targetApi="n">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="@string/admob_app_id" />
<activity
android:name=".view.activity.SplashActivity"
android:theme="@style/AppTheme.Splash"

View file

@ -16,6 +16,11 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.google.ads.mediation.admob.AdMobAdapter;
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.MobileAds;
import com.wbrawner.simplemarkdown.MarkdownApplication;
import com.wbrawner.simplemarkdown.R;
import com.wbrawner.simplemarkdown.presentation.MarkdownPresenter;
@ -44,6 +49,8 @@ public class MainActivity extends AppCompatActivity
DisableableViewPager pager;
@BindView(R.id.layout_tab)
TabLayout tabLayout;
@BindView(R.id.adView)
AdView adView;
private boolean shouldAutoSave = true;
private NewFileHandler newFileHandler;
@ -68,6 +75,25 @@ public class MainActivity extends AppCompatActivity
if (getIntent().getBooleanExtra(Constants.EXTRA_EXPLORER, false)) {
requestFileOp(Constants.REQUEST_OPEN_FILE);
}
// TODO: Change this to only load for users who haven't paid to remove ads
if (true) {
MobileAds.initialize(this, getString(R.string.admob_app_id));
Bundle extras = new Bundle();
extras.putString("npa", "1");
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("7045AFE2F8D6C6386983BAF3D2A2377E")
.addNetworkExtrasBundle(AdMobAdapter.class, extras)
.build();
adView.setAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int i) {
super.onAdFailedToLoad(i);
ACRA.getErrorReporter().handleException(new RuntimeException("Failed to load ads: " + i), false);
}
});
adView.loadAd(adRequest);
}
}
@Override

View file

@ -1,13 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.wbrawner.simplemarkdown.view.DisableableViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/adView">
<android.support.design.widget.TabLayout
android:id="@+id/layout_tab"
android:layout_width="match_parent"
@ -26,4 +30,15 @@
</android.support.design.widget.TabLayout>
</com.wbrawner.simplemarkdown.view.DisableableViewPager>
</LinearLayout>
<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="50dp"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/adbmob_ad_unit_id"
app:layout_constraintTop_toBottomOf="@+id/pager"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"></com.google.android.gms.ads.AdView>
</android.support.constraint.ConstraintLayout>

View file

@ -1,6 +1,9 @@
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
<string name="app_name">Simple Markdown</string>
<string name="app_name_short">Markdown</string>
<string name="admob_app_id">ca-app-pub-3319579963502409~4576405307</string>
<string name="action_settings">Settings</string>
<string name="action_help">Help</string>
<string name="action_edit">Edit</string>

View file

@ -7,8 +7,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.2.0'
}
}