Developing Android Applications with Adobe AIR [21]
You must subscribe to get an application ID. At runtime, your application makes a request to receive advertisement information. Indicate the ad’s format (XML is best) and dimensions. Some providers allow you to specify geolocation, age, or gender for targeted ads.
All providers give you an option to test your application with dummy ads before it goes live. Always put the advertisement code in a try catch block. You do not want your application to stop functioning because the provider server is down or sends bad data.
At the time of this writing, mobile advertising providers do not offer an AS3 SDK. You need to download the AS2 version and rewrite it for your purposes. Making straight calls in the standalone application does not seem to provide ad impressions. Instead, use the StageWebView API, which allows you to open a web page within your AIR application to simulate the browser experience. We will cover this topic in Chapter 13.
Reporting
Google Market tracks how many users have downloaded your application. But you may want to also know how users interact with your application. You could track, for instance, which part of your product is most popular and which features could be replaced or removed.
Reporting has become a standard component for many applications. This capability tracks user activity and sends the information to a remote service that stores data and provides analysis.
Google Analytics (http://www.google.com/analytics/), a popular choice in the nonenterprise market, is free and provides an open source ActionScript API. An ActionScript 3 API for Google Analytics data collection, called gaforflash, is available at http://code.google.com/p/gaforflash/. In addition, you can keep up with Google Analytics information by reading the blog athttp://analytics.blogspot.com/2011/01/new-actionscript-3-library-for-api.html.
You need to provide a website profile and some geographic information when you register on Google Analytics. A simple example follows.
To set the Internet permission:
To use the Web ID property you received from the service:
import com.google.analytics.GATracker;
import com.google.analytics.AnalyticsTracker;
var tracker:AnalyticsTracker =
new GATracker(this, "UA-111-222", "AS3", false);
// current displayObject
// Unique Web ID
// tracking mode
// debug mode
// button press go to section "game"
function pressButton(event:MouseEvent):void {
tracker.trackerPageView("game");
tracker.trackEvent("Button", "click", "parameter1", "parameter2");
// category
// action
// additional parameters as needed
}
Conclusion
The distribution model for AIR applications is constantly evolving. Keep informed of new channels. For best practices on mobile distribution, read Jonathan Campos’s article, “Learn from my mobile mistakes,” at http://unitedmindset.com/jonbcampos/2010/12/28/learn-from-my-mobile-mistakes/.
Chapter 5. Evaluating Device Capabilities and Handling Multiple Devices
The multitude which does not reduce itself to unity is confusion.
—Blaise Pascal
The premise of mobile AIR is to enable you to create one concept, one code base, and a set of assets to deploy an application on multiple devices effortlessly. AIR for mobile accomplishes this for the most part, but not without challenges. There is a disparity in performance and capabilities among devices, and deploying for a range of screen resolutions requires effort and time even if your art is minimal.
In the near future, mobile devices will approach, and perhaps surpass, the performance of desktop machines. Until then, you must adapt your development style to this limited environment. Every line of code and every asset should be scrutinized for optimization. The AIR runtime has been optimized for devices with limited resources, but this is no guarantee that your code will run smoothly. This part is your responsibility.
In this chapter, we will discuss how to evaluate device capabilities. We will then discuss how to handle multiple screens and