A Tutorial on Adding an AdMob Ad to an Android App
Displaying advertisements (ads) is one way of monetizing an App. To monetize (monetise) something is turn turn it into cash. That term applied to Apps and web pages refers to getting revenue through ads or paid content. Showing ads is one way of generating an income from the time and effort spent developing the App. Though a reasonably successful App is required to generate worthwhile funds. Other techniques include charging a price for the App and providing additional content within the App for a fee (In-App Billing).
Google makes it relatively easy to include ads into an App as the simple example code here shows. This tutorial should help those who may have found it difficult to get the example provided with the online AdMob documentation to work. It is assumed that your computer is configured for developing Apps using the Eclipse Integrated Development Environment (IDE) (see Set Up Windows for Android Development if not), and that you can create and run a simple App (see Your First Android Java Program if in doubt). All the steps required to get ad serving in your App working are covered. So read on to find out how to add AdMob to Android Apps.
Get an AdMob Account
You get a very small payment for each ad that is selected (clicked or pressed on) from a device that is running your App. So that Google can make that small payment it must identify in which App the ad was selected. This is done by placing a unique Publisher Id in the code that is showing the ads. To get the unique id for each App you need an AdMob account. Head over to http://www.google.com/ads/admob/ and sign up, you will need a Google account to register.
Target SDK Must be 3.2 or Higher
Your App is ready for publishing, lets put in the ad serving code so that when you activate it on Google Play it can (potentially) make you some money. In this tutorial we will add the code to an existing example project, in this case the code that was written for the article Two Line Lists In Android. You can also follow this tutorial but use your own App to add the code. Continue reading
A SimpleAdapter Loads a ListActivity with Two Line Entries
In the article Add a Simple List to an App example code was given to show how to load a ListActivity from a string array. This article shows how each list item in a ListActivity can display two lines of data, in this case each list item will be an American state and its capital. It is assumed that you know Java and that your computer is set up for Android development using Eclipse, if not see Set Up Windows for Android Development.
Start by creating a new Android Project in Eclipse using the File menu, select New then Android Project. Fill in the Project Name, here State Capitals is used. Click Next and select the build target from the installed APIs, e.g. Android 1.5, any of the installed APIs will work and it can be changed later if required. Click Next and enter the Package Name in the required format, e.g. biz.tekeye.statecapitals, leave Create Activity checked with the default Activity name, click Finish.
A common pattern in Android is to define a View in XML, set up the data that will be displayed in the View, then provide the code to load that data into the View. In the case of a ListView or ListActivity that code is provided by an Adapter. For a list with single line entries an ArrayAdapter does the job as seen in the previously mentioned article. Adding another line of data for each entry in the list requires the SimpleAdapter.
The code shown here will define a two dimensional string array to hold the American States names and capitals data. Two TextViews in a layout define the template for each list entry. The work of inflating the Views for each list entry and setting the values in the Views is done by a SimpleAdapter. An ArrayList and HashMap ensures the data goes into the correct TextView. This diagram summarises what the code achieves.
AVDs Failing to Start if Eclipse is Not on C:
At Eye our machines are built for performance, shaving seconds of the program – compile – test cycle saves hours over the month. Machines have a small solid state drive (SSD) for the Operating System (Win 7 x64) and a big hard disk drive (HDD) for programs and work data. So Win 7 is on a C: drive and everything else on a D: drive. All users’ special folders are relocated to D:. For Android development Eclipse is installed with the Android Development Tools (ADT) Plugin onto the D: drive.
A lot of the initial development of an App is done using an Android Virtual Device (AVD). The AVD is set up using the AVD Manager. Once set up an AVD allows an App to be launched onto it via the Eclipse Run or Debug options. Unfortunately on some configurations where the user folders are on the D: drive, an error is reported when an AVD tries to start (even if the AVD Manager successfully created the AVD). A Starting Android Emulator dialog appears with an error message similar to PANIC: Could not open: C:\Users\Name\.android/avd/AVDName.ini.
When debugging or running Apps ADT is trying to load the emulator from C: when it, and the configuration files for it, are on D:. One solution is to use a NTFS symbolic link, a.k.a a symlink. Setting up a symlink can fix the above error.
Open a command prompt in the user directory on C: (if you relocated all your special Windows folders to D: then there may only be a hidden Appdata folder in the user folder on C:). Use the mklink program to make a hard link to the .android directory on D:. If user John Doe moved all his Users files from C:\Users to D:\Users then the command to make the directory junction would be:
mklink /J "C:\Users\John Doe\.android" "D:\John Doe\.android"
Now when the ADT plugin is trying to reference .android on C: NTFS redirects the request to D: and the emulator starts correctly.
(The mklink command is not shipped with Windows XP, to create a Directory Junction on Windows XP us the Sysinternal Junction tool.)
A Tutorial on Moving User My Documents and Personal Folders to Another Drive
Each user on a Windows computer (Windows 8.1, Windows 8 and Windows 7 and earlier) is given a private location on the PC into which they can store their work. This work can be pictures, documents, music, emails, videos and anything else that they use or generate. It is private because other users cannot view their files (unless they are logged in as an Administrator). When a user logs on they can work with their private files and any Public files. To let other users see their work it needs be moved or copied into the relevant Public folders, or a directory needs to be marked as shared.
The default installation for Windows is to put all the users folders onto the same hard disk drive as the operating system itself, usually the first, and only, hard disk in the system, called the C: drive. This drive will also hold any additional programs that are installed. Each user is located under the Users folder on C:, so a user call John Doe has folders located at C:\Users\John Doe. Under the users main folder is a folder to store different types of files that programs generate or use. For example there is a Contacts folder (at C:\Users\John Doe\Contacts) to store, well, contacts (name, address, phone numbers, etc.). Use Windows Explorer to view the Users folders. Open Windows Explorer via the Start button, All Programs and Accessories, or in Windows 8.1 hold the Windows key and press E. The various folders created by Windows for the user can be seen under the user’s name from the Desktop icon (Windows 7) or under C:\Users\User Name in Windows 8.1.
Some of the folders are also accessible via the various Library icons. In Windows 7 in Explorer some folders begin with My, such as My Documents or My Music. However, the actual folder name on the hard disk does not have My, thus My Documents in Explorer points to C:\Users\John Doe\Documents. This table shows the folder name, the display name in Explorer and whether or not a public version is available, located at C:\Users\Public (this folder itself can be used to make files public).
||Win 7 Name in Explorer
|| Public Desktop
|| Public Documents
|| Public Downloads
|| Public Music
|| Public Pictures
|| Public Videos
Locating all the user folders on the one hard disk drive along with Windows and all the programs makes configuration and manufacture of a new computer easier. Unfortunately it has several disadvantages: Continue reading