Android

From Ad4Game Developers
Revision as of 06:27, 13 August 2013 by Mostapha (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Publishers

Download Android SDK

Download the [Android SDK] Media:Ad4game_AndroidSDK_FOR_Publishers.zip. Decompress the zip file and extract the files to your development computer.
The Android SDK is provided as a single java JAR file (AndroidSDKPublisher.jar), making it easy to include in your Android project.

Configure AndroidManifest.xml

The SDK requires the following permissions. Put these in before closing the manifest tag.
Internet Permission (Required):
The Internet permission is required to connect to publishing servers.

<uses­-permission android:name="android.permission.INTERNET"/>

Wifi State Permission (Required):
This permission enable the SDK to access information about whether you are connected to a Wi­Fi network and obtain the device’s MAC address.

<uses­-permission android:name="android.permission.ACCESS_WIFI_STATE" />

Tasks Permission (Required):
Allows the SDK to get information about the currently or recently running tasks to set the refresh value.

<uses­permission android:name="android.permission.GET_TASKS" />

Install the Android SDK

Add AndroidSDKPublisher.jar to your Android project's build path.
If you are using Eclipse, right click on your project folder ­> Properties ­> Java Build Path ­> Libraries ­> Add JARs.
(As of ADT 17.0, you can simply place AndroidSDKPublisher.jar in a folder called “libs” in your project directory and Eclipse will automatically include the jar as part of the build under the classpath container “Android Dependencies”) .

You need to set the value of "refresh" variable to refresh banners. You'll then need to instantiate the A4GPublisher class to allow you to call the functions from the AndroidSDKPublisher.
Generally, the code is placed inside your main activity’s onCreate(Bundle) method.
You will need to pass the layout ID to the findViewById method, and then call loadZoneId(“ZoneID”) method.

      

public class MyClass extends Activity {
public static int refresh = 30000; //30 seconds
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_a4g);
A4GPublisher widget = (A4GPublisher) findViewById(R.id.yourLayoutID);
widget.loadZoneId("ZoneID");
}
}


In your layout.xml file, you need to include the properties of the layout where you want to display the banners as follows


<com.a4gpublisher.A4GPublisher

android:id="@+id/yourLayoutID"
...
/>

Note: You can add many zones as you want, just instantiate the A4GPublisher object to create many widgets.

Example:

   
A4GPublisher widget1 = (A4GPublisher) findViewById(R.id.yourFirstLayoutID);
widget1.loadZoneId("ZoneID");

A4GPublisher widget2 = (A4GPublisher) findViewById(R.id.yourSecondLayoutID);
widget2.loadZoneId("ZoneID");

Advertisers

Download Android SDK

Download the Media:Ad4game_Android_SDK_for_advertisers.zip. Decompress the zip file and extract the files to your development computer.
The Android SDK is provided as a single java JAR file (AndroidSDKTracker.jar), making it easy to include in your Android project.

Install the Android SDK

Add AndroidSDKTracker.jar to your Android project's build path.
If you are using Eclipse, right click on your project folder ­> Properties ­> Java Build Path ­> Libraries ­> Add JARs.
(As of ADT 17.0, you can simply place AndroidSDKTracker.jar in a folder called “libs” in your project directory and Eclipse will automatically include the jar as part of the build under the classpath container “Android Dependencies”) .

Configure AndroidManifest.xml

The SDK requires the following permissions. Put these in before closing the manifest tag.

Internet Permission (Required):
The Internet permission is required to connect to tracking servers.

<uses­-permission android:name="android.permission.INTERNET"/>

Wifi State Permission (Required):
These permissions enable the SDK to access information about whether you are connected to a Wi­Fi network and obtain the device’s MAC address.

<uses-­permission android:name="android.permission.ACCESS_WIFI_STATE" />

The SDK requires setting up a Tracker receiver in your Android manifest. Put this receiver inside your application tags.



Install Referral (Required):
Gives the SDK access to the install referrer value from Google Play Store.

    

<receiver android:name="com.mypackage.MyReceiverClass" android:exported="true">
<intent­filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent­filter>
</receiver>


You need to create your ReceiverClass as follow:
yourReceiverClass extends the BroadcastReceiver. Inside the onReceive method, you need to instantiate the A4GTracking class, and then call the trackInstall method which has these parameters trackerID, context and intent.

    
public class MyReceiverClass extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
//Begin of tracking installs
A4GTracking a4g = new A4GTracking(context);
a4g.trackInstall("yourTrackerID", context, intent);
// End of tracking installs
}
}


In your onCreate method, you need to instantiate the A4GTracking class to allow you to call the functions from the AndroidSDKTracker.

   

public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Begin of tracking installs
//Instantiate the A4GTracking class
A4GTracking a4g = new A4GTracking(getApplicationContext());
//Load the SID
String SID = a4g.getSID(getApplicationContext());
if (SID == null) {
// Track installation
a4g.callTracker("yourTrackerID", SID, getApplicationContext());
//Store the SID with a default value
a4g.setSID("default Value", getApplicationContext());
}
// End of tracking installs
}
}

Contact

If you've got questions, we've got answers! Please Contact Us at "mobile@ad4game.com" with any technical queries.

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox