Skip to content

Commit bd6f7de

Browse files
author
Kalyan Reddy
committed
Porting admob and app indexing quickstarts.
(Forgot this was assigned to me -- oops!) Change-Id: If24cc6878be2c710606d123b4e2234cc5cd7605a
1 parent 2ecb0ad commit bd6f7de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1585
-0
lines changed

admob/.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.gradle
2+
/local.properties
3+
.DS_Store
4+
build/
5+
google-services.json
6+
7+
# Android Studio
8+
.idea
9+
*.iml

admob/.google/packaging.yaml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# GOOGLE SAMPLE PACKAGING DATA
2+
#
3+
# This file is used by Google as part of our samples packaging process.
4+
# End users may safely ignore this file. It has no relevance to other systems.
5+
---
6+
# Values: {DRAFT | PUBLISHED | INTERNAL | DEPRECATED | SUPERCEDED}
7+
status: DRAFT
8+
9+
# Optional, put additional explanation here for DEPRECATED or SUPERCEDED.
10+
# statusNote:
11+
12+
# See http://go/sample-categories
13+
technologies: [Android, Google Play Services, Google AdMob]
14+
categories: [Getting Started]
15+
languages: [Java]
16+
solutions: [Mobile]
17+
18+
# May be omitted if unpublished
19+
# github: google/actionbar-basics
20+
21+
# Values: BEGINNER | INTERMEDIATE | ADVANCED | EXPERT
22+
level: BEGINNER
23+
24+
# Dimensions: 512x512, PNG fomrat
25+
icon: app/src/main/res/drawable/ic_launcher_big.png
26+
27+
# List of APIs that this sample should be listed under. Use authoritive,
28+
# names that are unique for the product in question. Examples:
29+
#
30+
# Android - android:<class-name>
31+
# App Engine - gae-java:<class name>
32+
# gae-python:<package>
33+
# Web Services - ws:<name of API from Cloud Console>
34+
apiRefs:
35+
- android:com.google.android.gms.ads
36+
37+
# Default: apache2. May be omitted for most samples.
38+
# Alternatives: apache2-android (for AOSP)
39+
license: apache2

admob/README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Google AdMob Quickstart
2+
=======================
3+
4+
The Google AdMob Android quickstart demonstrates how to display an interstitial ad and
5+
a simple banner ad. AdRequest and AdView are used to display a banner ad
6+
and InterstitialAd is used to display the interstitial ad.
7+
8+
Introduction
9+
------------
10+
11+
- [Read more about Google AdMob](https://developers.google.com/admob/)
12+
13+
Getting Started
14+
---------------
15+
16+
- [Add Firebase to your Android Project](https://developers.google.com/firebase/docs/android/setup).
17+
- Follow the [quickstart guide](https://developers.google.com/admob/android/start) to set up your project in Android Studio.
18+
- Run the sample on your Android device or emulator.
19+
- The running sample displays a test banner ad and a test interstitial add.
20+
21+
Screenshots
22+
-----------
23+
![Screenshot](app/src/main/admob-sample.png)
24+
25+
Support
26+
-------
27+
28+
- Stack Overflow: http://stackoverflow.com/questions/tagged/admob
29+
- [Developer forum](groups.google.com/group/google-admob-ads-sdk)
30+
- [Firebase support](http://developers.google.com/firebase/support/)
31+
32+
If you've found an error in this sample, please file an issue:
33+
https://github.com/googlesamples/google-services/issues
34+
35+
Patches are encouraged, and may be submitted by forking this project and
36+
submitting a pull request through GitHub.
37+
38+
License
39+
-------
40+
41+
Copyright 2015 Google, Inc.
42+
43+
Licensed to the Apache Software Foundation (ASF) under one or more contributor
44+
license agreements. See the NOTICE file distributed with this work for
45+
additional information regarding copyright ownership. The ASF licenses this
46+
file to you under the Apache License, Version 2.0 (the "License"); you may not
47+
use this file except in compliance with the License. You may obtain a copy of
48+
the License at
49+
50+
http://www.apache.org/licenses/LICENSE-2.0
51+
52+
Unless required by applicable law or agreed to in writing, software
53+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
54+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
55+
License for the specific language governing permissions and limitations under
56+
the License.

admob/app/build.gradle

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.2"
6+
7+
defaultConfig {
8+
applicationId "com.google.samples.quickstart.admobexample"
9+
minSdkVersion 9
10+
targetSdkVersion 23
11+
versionCode 1
12+
versionName "1.0"
13+
14+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15+
}
16+
buildTypes {
17+
release {
18+
minifyEnabled false
19+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20+
}
21+
}
22+
packagingOptions {
23+
exclude 'LICENSE.txt'
24+
}
25+
}
26+
27+
dependencies {
28+
compile fileTree(dir: 'libs', include: ['*.jar'])
29+
// AppCompat
30+
compile 'com.android.support:appcompat-v7:23.0.0'
31+
32+
// [START gradle_play_config]
33+
compile 'com.google.android.gms:play-services-ads:8.5.1'
34+
// [END gradle_play_config]
35+
36+
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
37+
androidTestCompile 'com.android.support.test:runner:0.2'
38+
androidTestCompile 'com.android.support:support-annotations:23.0.0'
39+
}
40+
41+
apply plugin: 'com.google.gms.google-services'

admob/app/proguard-rules.pro

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/gkal/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.samples.quickstart.admobexample;
17+
18+
import android.test.ActivityInstrumentationTestCase2;
19+
import android.test.suitebuilder.annotation.LargeTest;
20+
21+
import static android.support.test.espresso.Espresso.onView;
22+
import static android.support.test.espresso.assertion.ViewAssertions.matches;
23+
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
24+
import static android.support.test.espresso.matcher.ViewMatchers.withId;
25+
26+
/**
27+
* An Espresso test for the MainActivity.
28+
*/
29+
@LargeTest
30+
public class MainActivityEspressoTest extends ActivityInstrumentationTestCase2<MainActivity> {
31+
32+
public MainActivityEspressoTest() {
33+
super(MainActivity.class);
34+
}
35+
36+
@Override
37+
public void setUp() throws Exception {
38+
super.setUp();
39+
getActivity();
40+
}
41+
42+
public void testContentVisibleOnActivityStart() {
43+
onView(withId(R.id.content)).check(matches(isDisplayed()));
44+
}
45+
46+
public void testAdViewVisibleOnActivityStart() {
47+
onView(withId(R.id.adView)).check(matches(isDisplayed()));
48+
}
49+
50+
}
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.google.samples.quickstart.admobexample" >
4+
5+
<!-- [SNIPPET modify_app_permissions]
6+
Include required permissions for Google Mobile Ads to run.
7+
[START modify_app_permissions] -->
8+
<uses-permission android:name="android.permission.INTERNET" />
9+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
10+
11+
<!-- [END modify_app_permissions] -->
12+
<application
13+
android:allowBackup="true"
14+
android:icon="@mipmap/ic_launcher"
15+
android:label="@string/app_name"
16+
android:theme="@style/AppTheme" >
17+
<activity
18+
android:name=".MainActivity"
19+
android:label="@string/app_name" >
20+
<intent-filter>
21+
<action android:name="android.intent.action.MAIN" />
22+
23+
<category android:name="android.intent.category.LAUNCHER" />
24+
</intent-filter>
25+
</activity>
26+
<!-- [SNIPPET add_activity_config_changes]
27+
Include the AdActivity configChanges and theme.
28+
[START add_activity_config_changes] -->
29+
<activity
30+
android:name="com.google.android.gms.ads.AdActivity"
31+
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
32+
android:theme="@android:style/Theme.Translucent" />
33+
<!-- [END add_activity_config_changes] -->
34+
<activity
35+
android:name=".SecondActivity"
36+
android:label="@string/second_activity_title"
37+
android:parentActivityName=".MainActivity" >
38+
<meta-data
39+
android:name="android.support.PARENT_ACTIVITY"
40+
android:value=".MainActivity" />
41+
</activity>
42+
</application>
43+
44+
</manifest>

admob/app/src/main/admob-sample.png

141 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/**
2+
* Copyright Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.samples.quickstart.admobexample;
17+
18+
import android.content.Intent;
19+
import android.os.Bundle;
20+
import android.support.v7.app.AppCompatActivity;
21+
import android.view.View;
22+
import android.widget.Button;
23+
import com.google.android.gms.ads.AdListener;
24+
// [SNIPPET load_banner_ad]
25+
// Load an ad into the AdView.
26+
// [START load_banner_ad]
27+
import com.google.android.gms.ads.AdRequest;
28+
import com.google.android.gms.ads.AdView;
29+
// [START_EXCLUDE]
30+
import com.google.android.gms.ads.InterstitialAd;
31+
// [END_EXCLUDE]
32+
33+
34+
public class MainActivity extends AppCompatActivity {
35+
36+
private AdView mAdView;
37+
// [START_EXCLUDE]
38+
private InterstitialAd mInterstitialAd;
39+
private Button mLoadInterstitialButton;
40+
// [END_EXCLUDE]
41+
42+
@Override
43+
protected void onCreate(Bundle savedInstanceState) {
44+
super.onCreate(savedInstanceState);
45+
setContentView(R.layout.activity_main);
46+
47+
mAdView = (AdView) findViewById(R.id.adView);
48+
AdRequest adRequest = new AdRequest.Builder().build();
49+
mAdView.loadAd(adRequest);
50+
// [END load_banner_ad]
51+
52+
// [START instantiate_interstitial_ad]
53+
// Create an InterstitialAd object. This same object can be re-used whenever you want to
54+
// show an interstitial.
55+
mInterstitialAd = new InterstitialAd(this);
56+
mInterstitialAd.setAdUnitId(getString(R.string.test_interstitial_ad_unit_id));
57+
// [END instantiate_interstitial_ad]
58+
59+
// [START create_interstitial_ad_listener]
60+
mInterstitialAd.setAdListener(new AdListener() {
61+
@Override
62+
public void onAdClosed() {
63+
requestNewInterstitial();
64+
beginSecondActivity();
65+
}
66+
});
67+
// [END create_interstitial_ad_listener]
68+
69+
// [START display_interstitial_ad]
70+
mLoadInterstitialButton = (Button) findViewById(R.id.load_interstitial_button);
71+
mLoadInterstitialButton.setOnClickListener(new View.OnClickListener() {
72+
@Override
73+
public void onClick(View v) {
74+
if (mInterstitialAd.isLoaded()) {
75+
mInterstitialAd.show();
76+
} else {
77+
beginSecondActivity();
78+
}
79+
}
80+
});
81+
// [END display_interstitial_ad]
82+
}
83+
84+
/**
85+
* Load a new interstitial ad asynchronously.
86+
*/
87+
// [START request_new_interstitial]
88+
private void requestNewInterstitial() {
89+
AdRequest adRequest = new AdRequest.Builder()
90+
.build();
91+
92+
mInterstitialAd.loadAd(adRequest);
93+
}
94+
// [END request_new_interstitial]
95+
96+
private void beginSecondActivity() {
97+
Intent intent = new Intent(this, SecondActivity.class);
98+
startActivity(intent);
99+
}
100+
101+
// [START add_lifecycle_methods]
102+
/** Called when leaving the activity */
103+
@Override
104+
public void onPause() {
105+
if (mAdView != null) {
106+
mAdView.pause();
107+
}
108+
super.onPause();
109+
}
110+
111+
/** Called when returning to the activity */
112+
@Override
113+
public void onResume() {
114+
super.onResume();
115+
if (mAdView != null) {
116+
mAdView.resume();
117+
}
118+
if (!mInterstitialAd.isLoaded()) {
119+
requestNewInterstitial();
120+
}
121+
}
122+
123+
/** Called before the activity is destroyed */
124+
@Override
125+
public void onDestroy() {
126+
if (mAdView != null) {
127+
mAdView.destroy();
128+
}
129+
super.onDestroy();
130+
}
131+
// [END add_lifecycle_methods]
132+
}

0 commit comments

Comments
 (0)