Skip to content

Commit

Permalink
add admob sdk (#8)
Browse files Browse the repository at this point in the history
* add admob sdk

* update readme

* remove comment

* fix build.gradle

* Update README.md
  • Loading branch information
testica committed Aug 31, 2018
1 parent 3508d5e commit 8fdb28d
Show file tree
Hide file tree
Showing 7 changed files with 384 additions and 328 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ OCR Android App using tesseract
- [android-image-cropper](https://github.com/ArthurHub/Android-Image-Cropper): for image cropping.
- [tess-two](https://github.com/rmtheis/tess-two): to recognize text (tesseract) and binarize (leptonica).
- [firebase](https://firebase.google.com/docs/android/setup): to report metrics (for development purpose, you can [remove firebase dependencies](https://github.com/testica/text-scanner/pull/5) or add your own google-services.json).
- [admob](https://developers.google.com/admob/android/quick-start): to show google ads (to pay some bills). Check [PR #8](https://github.com/testica/text-scanner/pull/8) to know more about admob environment.

## Support
- Android 4.0 +
Expand Down
12 changes: 10 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ android {
targetSdkVersion 26
versionCode 3
versionName "1.2"

buildConfigField 'String', 'AdMobAppId', '"ca-app-pub-3940256099942544~3347511713"'
resValue 'string', 'admob_app_id', '"ca-app-pub-3940256099942544~3347511713"'
resValue 'string', 'admob_unit_id', '"ca-app-pub-3940256099942544/6300978111"'
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField 'String', 'AdMobAppId', TextScanner_AdMobAppId
resValue 'string', 'admob_app_id', TextScanner_AdMobAppId
resValue 'string', 'admob_unit_id', TextScanner_AdMobUnitId
}
}
}
Expand All @@ -26,10 +33,11 @@ dependencies {
implementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.4'
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
implementation 'com.rmtheis:tess-two:6.0.4'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.3.1'
implementation 'com.google.firebase:firebase-ads:15.0.1'
}

apply plugin: 'com.google.gms.google-services'
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -26,6 +27,9 @@
<activity
android:name=".Recognizer"
android:configChanges="keyboardHidden|orientation|screenSize" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="@string/admob_app_id"/>
</application>


Expand Down
14 changes: 13 additions & 1 deletion app/src/main/java/com/ltapps/textscanner/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -26,6 +30,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private Uri outputFileUri;
private View mView;
public final static String EXTRA_MESSAGE = "com.ltapps.textscanner.message";
private AdView mAdView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -37,6 +43,12 @@ protected void onCreate(Bundle savedInstanceState) {
mView = findViewById(R.id.mainView);
mView.setOnClickListener(this);

// AdMob App ID
MobileAds.initialize(this, BuildConfig.AdMobAppId);
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

if (ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
Expand All @@ -45,7 +57,7 @@ protected void onCreate(Bundle savedInstanceState) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

// Show an expanation to the user *asynchronously* -- don't block
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.

Expand Down
Loading

0 comments on commit 8fdb28d

Please sign in to comment.