SlideShare a Scribd company logo
Advertising Integration
MPointInc SDK for Android
Prepared by:Xin Shao, Java Developer
July 29, 2015
Ads Integration for Android
Adding one ads to your app takes just a few lines of code. 

Import MPointInc_SDK
I. For Eclipse ADT
To add a reference to MPointInc SDK, follow these steps:

	 1. Make sure that both the MPointInc SDK and the application project that depends
	 on it are in your workspace. If one of the projects is missing, import it into your 	
	 workspace.

	 2. In the Package Explorer, right-click the your project and select Properties.

	 3. In the Properties window, select the "Android" properties group at left and locate
	 the Library properties at right.

	 4. Click Add to open the Project Selection dialog.

	 5. From the list of available library projects, select MPointInc_SDK and click OK.

	 6. When the dialog closes, click Apply in the Properties window.

	 7. Click OK to close the Properties window.

As soon as the Properties dialog closes, Eclipse rebuilds the project, including the contents
of the library project.
Figure 1 shows the Properties dialog that lets you add library references and move them up
and down in priority.



Figure 1. Adding a reference to a library project in the properties of your project.

If you are adding references to multiple libraries, note that you can set their relative priority
(and merge order) by selecting a library and using the Up and Down controls. The tools
merge the referenced libraries with your application starting from lowest priority (bottom of
the list) to highest (top of the list). If more than one library defines the same resource ID, the
tools select the resource from the library with higher priority. The application itself has
highest priority and its resources are always used in preference to identical resource IDs
defined in libraries.

Reference: http://developer.android.com/tools/projects/projects-eclipse.html
II. For Android Studio
To import MPointInc SDK into your project, follow these steps:

	 	 1. From the main menu, select File | New | Import Module.

	 	 2. In the dialog that opens, browse to the MPointInc_SDK file and click OK. The
module node will be added to the tree view.

	 	 3. Add dependencies on the MPointInc SDK module to the your modules:

	 	 1. Open the settings of the your main module: navigate to File | Project
Structure, select Modules in the left pane and select your module in the
central pane.

	 	 2. In the right pane, switch to the Dependencies tab. Click the Add button +
on the left bottom and select Module Dependency from the context menu.

	 	 3. In the Choose Modules dialog box that opens, select the MPointInc SDK
module from the list and click OK.

Figure 2. Import Module in Project Structure of your project.

Reference: https://www.jetbrains.com/idea/help/sharing-android-source-code-and-
resources-using-library-projects.html
Import JSON file “userinfo.json”
// (How to get userinfo.json)——to be written
I. For Eclipse ADT
Copy the userinfo.json file into your application’s assets folder

II. For Android Studio
Copy the userinfo.json file into your application or main module’s assets folder, if there is no
assets folder you should create by yourself. Usually put the folder in “/src/main/assets” in
the main module.

Figure 3. Copy userinfo.json in assets folder in Android Studio
Load ads in your app
1. Check your AndroidManifest.xml file
Add the following permission in your main AndroidManifest.xml file:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
2. Initial the Device Information
At the very beginning the SDK need get some fundamental information from the device. In
your FIRST Activity’s onCreate() or your FIRST Fragment’s onCreateView() method,
add the following code as a the top priority and do this only once

MPointConstants.initialInfo(this);
3. Define a slot for your ad in your layout XML
The MPointInc SDK provides a custom View subclass, MPointView, that handles requesting
and loading ads.

Start by including this XML block to your Activity’s or Fragment’s layout. The attribute of
layout_height and layout_width should not be modified.

<com.mpointinc.mobileads.MPointView
android:id="@+id/mPointView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
4. Load an ad into the slot
Next, in your Activity or Fragment code, declare an instance variable for your MPointView:

private MPointView mAdsView;
You should already have created an ad unit on MPointInc’s site and received an Ad Unit ID.
You’ll use it now to identify that ad unit in your app and request ads from MPointInc that are
relevant for your users.

In your Activity’s onCreate() or your Fragment’s onCreateView() method, set your
MPointView’s AdsType.XXXX, we have BANNER, INTERSTITIAL, NATIVE and VIDEO, then
simply call loadAd(this) to fetch and display the ad:

...
mAdsView = (MPointView) findViewById(R.id.mPointView);
mAdsView.setAdType(AdsType.BANNER); // Set Ads Type. We have BANNER,
INTERSTITIAL, VIDEO and NATIVE
mAdsView.loadAd(this);
...
When the hosting Activity or Fragment is destroyed, be sure to also destroy the MPointView
by calling:

mAdsView.destroyAdsView();
Note
Eclipse sometimes adds an import android.R statement at the top of your files that use
resources, especially when you ask Eclipse to sort or otherwise manage imports. This may
cause your build to break; you can fix this by deleting the import statement.

More Related Content

PPTX
Create your First Watchkit App
PDF
Android Basic- CMC
PDF
Sensors in Android (old)
PDF
Training android
PPTX
Android Workshop: Day 1 Part 3
PPTX
How to create android applications
PPT
Day: 2 Environment Setup for Android Application Development
PPT
Multiple Activity and Navigation Primer
Create your First Watchkit App
Android Basic- CMC
Sensors in Android (old)
Training android
Android Workshop: Day 1 Part 3
How to create android applications
Day: 2 Environment Setup for Android Application Development
Multiple Activity and Navigation Primer

What's hot (17)

PDF
AndroidManifest
PPTX
Android
PPTX
Android 1.8 sensor
DOCX
Hospital app project (how to upload app)
PPT
Android Tutorial
PPTX
Android application-component
PPT
DSDP Mobile Tools for Java Webinar
PPTX
Android studio installation
PPT
Day 3: Getting Active Through Activities
PDF
Latch Drupal 6 english
PDF
I phone first app ducat
PPT
Day 4: Android: Getting Active through Activities
PDF
Android developer interview questions with answers pdf
PPTX
Write an application that draws basic graphical primitives.pptx
PPTX
GDG School Android Workshop
PDF
Trimantra - Project Portfolio_NET
PPT
Getting started with android studio
AndroidManifest
Android
Android 1.8 sensor
Hospital app project (how to upload app)
Android Tutorial
Android application-component
DSDP Mobile Tools for Java Webinar
Android studio installation
Day 3: Getting Active Through Activities
Latch Drupal 6 english
I phone first app ducat
Day 4: Android: Getting Active through Activities
Android developer interview questions with answers pdf
Write an application that draws basic graphical primitives.pptx
GDG School Android Workshop
Trimantra - Project Portfolio_NET
Getting started with android studio
Ad

Similar to MPointInc_AndroidSDK_Documentation (20)

DOC
Tang doanh thu quang cao di dong
PPTX
I/O Rewind 215: What's new in Android
PDF
INTRODUCTION TO FORMS OF SERVICES AND ITS LIFE CYCLE
PDF
Обзор Android M
PDF
Android Training Institute, Ghaziabad
PDF
HTML5 vs Native Android: Smart Enterprises for the Future
PDF
Making money with android applications
PDF
An Introduction To Android
PDF
Android development - the basics, MFF UK, 2012
PPTX
Introduction to Android Development
PDF
Android development - the basics, MFF UK, 2014
PPTX
Connecting Xamarin Apps with IBM Worklight in Bluemix
 
PPTX
MAD Unit 6.pptx
PPT
Beginning Native Android Apps
PPTX
Ibm xamarin gtruty
PPTX
IBM Worklight for Digital Agencies
PPTX
PDF
Android Application Development Programming With The Google Sdk 1st Edition R...
PPT
Android tutorial for beginners-traininginbangalore.com
PDF
Android industrial mobility
Tang doanh thu quang cao di dong
I/O Rewind 215: What's new in Android
INTRODUCTION TO FORMS OF SERVICES AND ITS LIFE CYCLE
Обзор Android M
Android Training Institute, Ghaziabad
HTML5 vs Native Android: Smart Enterprises for the Future
Making money with android applications
An Introduction To Android
Android development - the basics, MFF UK, 2012
Introduction to Android Development
Android development - the basics, MFF UK, 2014
Connecting Xamarin Apps with IBM Worklight in Bluemix
 
MAD Unit 6.pptx
Beginning Native Android Apps
Ibm xamarin gtruty
IBM Worklight for Digital Agencies
Android Application Development Programming With The Google Sdk 1st Edition R...
Android tutorial for beginners-traininginbangalore.com
Android industrial mobility
Ad

MPointInc_AndroidSDK_Documentation

  • 1. Advertising Integration MPointInc SDK for Android Prepared by:Xin Shao, Java Developer July 29, 2015 Ads Integration for Android Adding one ads to your app takes just a few lines of code. Import MPointInc_SDK I. For Eclipse ADT To add a reference to MPointInc SDK, follow these steps: 1. Make sure that both the MPointInc SDK and the application project that depends on it are in your workspace. If one of the projects is missing, import it into your workspace. 2. In the Package Explorer, right-click the your project and select Properties. 3. In the Properties window, select the "Android" properties group at left and locate the Library properties at right. 4. Click Add to open the Project Selection dialog. 5. From the list of available library projects, select MPointInc_SDK and click OK. 6. When the dialog closes, click Apply in the Properties window. 7. Click OK to close the Properties window. As soon as the Properties dialog closes, Eclipse rebuilds the project, including the contents of the library project.
  • 2. Figure 1 shows the Properties dialog that lets you add library references and move them up and down in priority. Figure 1. Adding a reference to a library project in the properties of your project. If you are adding references to multiple libraries, note that you can set their relative priority (and merge order) by selecting a library and using the Up and Down controls. The tools merge the referenced libraries with your application starting from lowest priority (bottom of the list) to highest (top of the list). If more than one library defines the same resource ID, the tools select the resource from the library with higher priority. The application itself has highest priority and its resources are always used in preference to identical resource IDs defined in libraries. Reference: http://developer.android.com/tools/projects/projects-eclipse.html
  • 3. II. For Android Studio To import MPointInc SDK into your project, follow these steps: 1. From the main menu, select File | New | Import Module. 2. In the dialog that opens, browse to the MPointInc_SDK file and click OK. The module node will be added to the tree view. 3. Add dependencies on the MPointInc SDK module to the your modules: 1. Open the settings of the your main module: navigate to File | Project Structure, select Modules in the left pane and select your module in the central pane. 2. In the right pane, switch to the Dependencies tab. Click the Add button + on the left bottom and select Module Dependency from the context menu. 3. In the Choose Modules dialog box that opens, select the MPointInc SDK module from the list and click OK. Figure 2. Import Module in Project Structure of your project. Reference: https://www.jetbrains.com/idea/help/sharing-android-source-code-and- resources-using-library-projects.html
  • 4. Import JSON file “userinfo.json” // (How to get userinfo.json)——to be written I. For Eclipse ADT Copy the userinfo.json file into your application’s assets folder II. For Android Studio Copy the userinfo.json file into your application or main module’s assets folder, if there is no assets folder you should create by yourself. Usually put the folder in “/src/main/assets” in the main module. Figure 3. Copy userinfo.json in assets folder in Android Studio
  • 5. Load ads in your app 1. Check your AndroidManifest.xml file Add the following permission in your main AndroidManifest.xml file: <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> 2. Initial the Device Information At the very beginning the SDK need get some fundamental information from the device. In your FIRST Activity’s onCreate() or your FIRST Fragment’s onCreateView() method, add the following code as a the top priority and do this only once MPointConstants.initialInfo(this); 3. Define a slot for your ad in your layout XML The MPointInc SDK provides a custom View subclass, MPointView, that handles requesting and loading ads. Start by including this XML block to your Activity’s or Fragment’s layout. The attribute of layout_height and layout_width should not be modified. <com.mpointinc.mobileads.MPointView android:id="@+id/mPointView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true"/> 4. Load an ad into the slot Next, in your Activity or Fragment code, declare an instance variable for your MPointView: private MPointView mAdsView; You should already have created an ad unit on MPointInc’s site and received an Ad Unit ID. You’ll use it now to identify that ad unit in your app and request ads from MPointInc that are relevant for your users. In your Activity’s onCreate() or your Fragment’s onCreateView() method, set your MPointView’s AdsType.XXXX, we have BANNER, INTERSTITIAL, NATIVE and VIDEO, then simply call loadAd(this) to fetch and display the ad: ... mAdsView = (MPointView) findViewById(R.id.mPointView);
  • 6. mAdsView.setAdType(AdsType.BANNER); // Set Ads Type. We have BANNER, INTERSTITIAL, VIDEO and NATIVE mAdsView.loadAd(this); ... When the hosting Activity or Fragment is destroyed, be sure to also destroy the MPointView by calling: mAdsView.destroyAdsView(); Note Eclipse sometimes adds an import android.R statement at the top of your files that use resources, especially when you ask Eclipse to sort or otherwise manage imports. This may cause your build to break; you can fix this by deleting the import statement.