Transcript 5.Intents

Mobile Computing
Monetizing An App
1
Copyright 2014 by Janson Industries
Objectives
▀
Learn about:
 The
 Ad
various ad companies
measurements
 AdViews
 Define
an ad using XML and java
2
Copyright 2014 by Janson Industries
Ad Companies
▀
▀
▀
AdMob, Inmobi, Mopub,
Jumptap, Tapit, Smaato,
Mobfox, AdSense
They provide code that you
add to your app
Their code figures out size of
ad to display based on the
device
3
Copyright 2014 by Janson Industries
Measurements
▀
CTR – click through rate
%
of people who click on an ad
► If
the ad is displayed 100 times and is
clicked twice, the ctr is 2% or .02
▀
CPC – cost per click
 How
much advertiser will pay you
for each click
► 47
cents for each click through
4
Copyright 2014 by Janson Industries
Measurements
▀
eCPM – effective cost per
thousand ad views (impressions)
 How
much you should make for a
thousand ads being displayed
 Need
to multiply CPC (.47) by 1000
by CTR (.02)
► .47
▀
Copyright 2014 by Janson Industries
* 1000 * .02 = $9.40
Ad companies track all these
measurements (and report them
to you)
5
Admob provides reports
6
Copyright 2014 by Janson Industries
Notice reported stats
7
Copyright 2014 by Janson Industries
Detailed stats
8
Copyright 2014 by Janson Industries
My sad, unpopular app
9
Copyright 2014 by Janson Industries
Measurements
▀
▀
Most of the ad companies won’t let
you post these numbers
Also, if they see unusual numbers:
A
CTR of 57%
 Clicks
are done by a small % of
users or locations
► They
may shut down your app
• People have their friends, relatives, and
neighbors download app and click ads
10
Copyright 2014 by Janson Industries
Going to use AdMob (owned by Google)
http://www.google.com/ads/admob/
11
Copyright 2014 by Janson Industries
Sign up using your google account
12
Copyright 2014 by Janson Industries
If you are at the same computer that you created the account on they
will know who you are!
If so, fill in the password
13
Copyright 2014 by Janson Industries
14
Copyright 2014 by Janson Industries
Specify info for an Admob account then click Continue
15
Copyright 2014 by Janson Industries
Scroll down, accept Terms, click Submit
16
Copyright 2014 by Janson Industries
Click Add Your First App
17
Copyright 2014 by Janson Industries
Specify tax and payment info, the click Submit
18
Copyright 2014 by Janson Industries
Click Sites and Apps then Android App
19
Copyright 2014 by Janson Industries
Fill in app info and click Continue
20
Copyright 2014 by Janson Industries
Go to https://apps.admob.com/#home click Monetize new app
21
Copyright 2014 by Janson Industries
Specify Project name and Android
22
Copyright 2014 by Janson Industries
Specify Ad type and give it a name
23
Copyright 2014 by Janson Industries
You can change some ad formatting
24
Copyright 2014 by Janson Industries
You need the add unit ID and you can have them info email to you
25
Copyright 2014 by Janson Industries
Specify email address to send to
26
Copyright 2014 by Janson Industries
The Ad unit ID that you will need to get ads
27
Copyright 2014 by Janson Industries
Go back to Home, scroll down, and the project(s) should be displayed
28
Copyright 2014 by Janson Industries
Creating From Scratch
▀
Must create a new project
(AdProj) with a min target of 3.2,
package (my.ad.com), activity
(AdProjActivity), and layout
(main)
 Example
▀
will be 4.X
Need to:
 Add
a reference to the Google play
services library
 Modify
the Manifest
29
Copyright 2014 by Janson Industries
30
Copyright 2014 by Janson Industries
Must import google-play-services_lib into the workspace
(Should already be there from MapProj but if not…)
File, Import, expand the Android folder and select
Existing Android Code Into WorkSpace, then click Next
31
Copyright 2014 by Janson Industries
Click the Browse button then navigate to the
sdk/extras/google/google_play_services/libproject/google
-play-services_lib, click OK then Finish
32
Copyright 2014 by Janson Industries
Right click AdProj and select Properties
Click Android
33
Copyright 2014 by Janson Industries
Scroll down, click Add, then select the library and click
OK
34
Copyright 2014 by Janson Industries
Setup
▀
Manifest have:
The
following meta tag in the
application element
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
The
following activity defined
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientat
ion|screenLayout|uiMode|screenSize|smallestScreenSize"/>
35
Copyright 2014 by Janson Industries
36
Copyright 2014 by Janson Industries
Setup
The
following permissions
outside the application tags
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"/>
37
Copyright 2014 by Janson Industries
38
Copyright 2014 by Janson Industries
Defining an Ad
▀
Use an AdView component
▀
Two ways to define an AdView
▀
 With
xml in the layout
 With
java in the activity
Will define an AdView
component in xml
39
Copyright 2014 by Janson Industries
main.xml
Don’t forget to substitute your Ad Unit ID in the adUnitId parameter
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-6333216089167186/1679833953"
ads:adSize="BANNER"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
40
</LinearLayout>
Copyright 2014 by Janson Industries
AdProjActivity.java
▀
Need to import
import com.google.android.gms.ads.*;
▀
Need an AdView variable and
object in onCreate then
 After
setContentView, create an
AdRequest and add a test device
 Load
ad into adView
// Look up the AdView as a resource and load a request.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("abc")
.build();
adView.loadAd(adRequest);
Copyright 2014 by Janson
Industries
41
AdProjActivity.java
▀
You will get a test ad
 Google
doesn't want you to
download real ads while testing
▀
To get a real add
// Look up the AdView as a resource and load a request.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
//.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
//.addTestDevice("abc")
.build();
adView.loadAd(adRequest);
42
Copyright 2014 by Janson Industries
AdProjActivity.java
▀
▀
Have to run to get a real
TestDevice number
Find in logcat
43
Copyright 2014 by Janson Industries
AdProjActivity.java
▀
Substitute for abc
// Look up the AdView as a resource and load a request.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("B3EEABB8EE11C2BE770B684D95219ECB")
.build();
adView.loadAd(adRequest);
44
Copyright 2014 by Janson Industries
45
Copyright 2014 by Janson Industries
ads:adSize="SMART_BANNER"
46
Copyright 2014 by Janson Industries
ads:adSize="MEDIUM_RECTANGLE"
47
Copyright 2014 by Janson Industries
Other Types of Ad

Interstitial Ads
 Full
screen ads with a close button
 More
expensive, therefore there are
often display limits
48
Copyright 2014 by Janson Industries
Go back to AdMob and add an Interstatial add to the app
49
Copyright 2014 by Janson Industries
Specify timeout and ad name
50
Copyright 2014 by Janson Industries
51
Copyright 2014 by Janson Industries
52
Copyright 2014 by Janson Industries
53
Copyright 2014 by Janson Industries
Interstitial

Need class level variables
private InterstitialAd interstitial;
private static final String AD_UNIT_ID = "ca-app-pub6333216089167186/1679833953";

In onCreate, create an InterstitialAd
object, set the Ad Unit ID, create
the AdRequest and load the ad
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(AD_UNIT_ID);
// Create ad request.
AdRequest adRequest = new AdRequest.Builder().build();
// Begin loading the interstitial
interstitial.loadAd(adRequest);
Copyright 2014 by Janson Industries
54
Interstitial Ads



Can take a while to load
If you try to display before loaded
will get an error
So we will put a button on the
screen and show the ad after the
button is touched
55
Copyright 2014 by Janson Industries
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="100px">
<Button
android:id="@+id/Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="doClick"
android:text="Show Ad" />
</LinearLayout>
56
</LinearLayout>
Copyright 2014 by Janson Industries
main.xml
doClick in AdProjActivity
import android.view.View;
:
:
:
public void doClick(View arg0) {
interstitial.show();
}

Time to test
57
Copyright 2014 by Janson Industries
Check in logcat that ad has loaded
58
Copyright 2014 by Janson Industries
Click Show Ad
59
Copyright 2014 by Janson Industries
AdListeners


In java, Activity can implement
the AdListener interface
Then tie the ad listener to the
adView
adView.setAdListener(this);
60
Copyright 2014 by Janson Industries
AdListeners

Activity can implement onAdxxx
methods that are called when ad is:
 Successfully
and unsuccessfully
received
 onAdLoaded,
 When
onAdFailedToLoad
ad is overlaid on the screen
 onAdOpened
 Ad
dismissed and returning to app
 onAdClosed
 When
ad clicked
 onAdLeftApplication
61
Copyright 2014 by Janson Industries
AdListeners

So instead of having a button to
display the ad
 Create
onAdLoaded method and have it
display the ad

And if ad doesn't load
 Create
onFailedToLoad method to retry
to load the ad
62
Copyright 2014 by Janson Industries