UC Union SDK (for Android) Setup Instruction

From UC Union Wiki
Jump to: navigation, search

1. Android version UC Union SDK supports

UC Union SDK supports Android 2.3+ version

If you use unity3d to create app, please visit here to integrate our SDK.

2. Set up UC Union SDK

1. Add and quote Umobi Ad SDK Service Library Project in your Eclipse Work spaces

2. Add and claim that com.umobi.android.embed browser.EmbedBrowserActivity in AndroidManifest.xml list

3. Add and claim Monitor of NetworkStateReceiver in AndroidManifest.xml List

4. Add com.umobi.android.ad.service.CurtainBallService in AndroidManifest.xml list

5. Add com.umobi.android.ad.service.MysteriousAdService service in AndroidManifest.xml list

6. Add com.umobi.android.ad.service.AppwallService service in AndroidManifest.xml list

7. set network permission in list

Embed SDK package in new project

Put umobisdk_x.x.x.jar in the category ‘libs’of project

Apply AndroidManifest.xml for setting

Developers are required to embed BrowserActivity in com.umobi.android. of AndroidManifest.xml when adding AdView

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.company"
 android:versionCode="1" android:versionName="1.0">

   <application android:label="@string/app_name">
     <activity android:label="@string/app_name" android:name=“Banner Example">
       <intent-filter>
          <action android:name="android.intent.action.MAIN"/>
          <category android:name="android.intent.category.LAUNCHER"/>
       </intent-filter>
     </activity>
     <activity android:name="com.umobi.android.embedbrowser.EmbedBrowserActivity"
        android:theme="@android:style/Theme.NoTitleBar"
        android:configChanges="keyboard|keyboardHidden|orientation"/>
   </application>
</manifest>

and add monitor of com.umobi.android.ad.util.NetworkStateReceiver

<activity
android:name="com.umobi.android.embedbrowser.EmbedBrowserActivity"
    android:theme="@android:style/Theme.NoTitleBar"

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode"/>
  <receiver android:name="com.umobi.android.ad.util.NetworkStateReceiver">

      <intent-filter>
        <action
android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
      </intent-filter>
    </receiver>

Network permission INTERNET,ACCESS_NETWOR_STATE and ACCESS_WIFI_STATE, together with reading and writing data access SYSTEM_ALERT_WINDOW and WRITE_EXTERNAL_STORAGE are required before sending AdRequest. In AndroidManifest.xml, the statement should be written as follow:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

You may also need to add AndroidManifest.xml in com.umobi.android.ad.service.CurtainBallService

<service android:name=“com.umobi.android.ad.service.CurtainBallService”/>

Partners using 0.7.0+ version may need to revise AppwallService in AndroidManifast.xml

Please take Integrate one-time entrance MysteriousAd for APP WALL (SDK 0.7.0+ version) for reference

Code Example

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.company"
  android:versionCode="1" android:versionName="1.0">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<application android:label="@string/app_name">
    <activity android:label="@string/app_name" android:name=“Banner Example">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
      <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
  </activity>
  <activity android:name="com.umobi.android.embedbrowser.EmbedBrowserActivity"
android:theme="@android:style/Theme.NoTitleBar"

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode "/>
  <receiver android:name=“com.umobi.android.ad.util.NetworkStateReceiver">
    <intent-filter>
      <action android:name=“android.net.conn.CONNECTIVITY_CHANGE”/>
    </intent-filter>
  </receiver>
  <service android:name=“com.umobi.android.ad.service.CurtainBallService”/>
        <service android:name="com.umobi.android.ad.service.MysteriousAdService" />
        <service android:name="com.umobi.android.ad.service.AppwallService" />

  </application>
</manifest>

3. Banner Ad

• Import com.umobi.android.ad*

• Declare an Adview instance

• Create it

• Add the view to the UI

• Load it with an ad

It would be more convenient to complete the above procedures in your application's Activity.

import com.umobi.android.ad.*;

public class BannerExample extends Activity {

  private AdView adView;
  @Override

  public void onCreate(Bundle savedInstanceState) {
    
    super.onCreate(savedInstanceState);
 
    setContentView(R.layout.main);
    // Create the adView

    adView = new AdView(this, AdSize.BANNER);
    // Lookup your LinearLayout, assuming it’s been given

    // the attribute android:id="@+id/mainLayout"

    LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);

    // Add the adView in it
    
    layout.addView(adView);
    // Initiate a generic request to load it with an ad

    AdRequest adRequest = new AdRequest(); 
    
    // Set up pub

    adRequest.setPub("demo@pub”);

    adView.loadAd(adRequest);
  } 

}

AdSize can use BANNER or SMART_BANNER as Ads placeholder on the screen.

AdSize.BANNER Original banner
AdSize.SMART_BANNER Banner size as screen width


Create your banner in XML

Rather than using Java, it's also possible to add an AdView in XML. Here is a summary of the steps in the code:

•Incorporate umobisdk_x.x.x.jar from the SDK into your application

•Define a com.umobi.android.ad.AdView in res/layout/main.xml

Defining com.umobi.android.ad.AdView

The easiest way to incorporate an ad is to simply define your AdView as you do for any other part of your res/layout/main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"> 
    <com.umobi.android.ad.AdView  android:id="@+id/adView"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     umobiad:adPub = "pub@demo"
   umobiad:adSize = "BANNER"/>
/>
</LinearLayout>

Look up and Load

To load AdRequest of ads, look up the AdView by searching resource via findViewById and invoke loadAd:

import com.umobi.android.ad.*;

public class BannerExample extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Look up the AdView as a resource and load a request.
    AdView adView = (AdView)this.findViewById(R.id.adView);  
  }
}

Methods to control AdView display

Developers can control Ad display and Ad click,Ad replacement via AdListener by callback and are entitle to cope with the above action.

Method Type Callback Arguments Description
onAdClosed void - When Ad closed
onAdFailedToLoad void errorCode:int When Ad failed to load
onAdLoaded void - When Ad loaded
onAdOpened void - When Ad opened
onAdPlay void msg:Message When Ad play
When Ad clicked void msg:Message When Ad clicked

import com.umobi.android.ad.*;

public class BannerExample extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Look up the AdView as a resource and load a request.
        AdView adView = (AdView)this.findViewById(R.id.adView);  
        AdRequest adRequest = new AdRequest(); 
        adRequest.setPub("demo@pub");
        adView.loadAd(adRequest);
        adView.setAdListener(new AdListener(){
            @Override
            public void onAdLoaded(){
                adView.show();
                //other code in here.
            }
            @Override
            public void onAdPlay(Message msg){
                //code here
            }
        });
    }
}

Lazy Mode

Except the above code to load Ad view, WindowManager, placed at the bottom of the Activity, can create an Ad view by AdView.simpleShow method:

import com.umobi.android.ad.*;

public class BannerExample extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Look up the AdView as a resource and load a request.
        AdView.simpleShow(this,"demo@pub");
    }
}

4. Create InterstitialAd

UC union supports InterstitialAd in SDK. If you need InterstitialAd in your Android APP, you are required to add com.umobi.android.ad.IntertitialAd in your interface.

The action to add com.umobi.android.ad.InterstitialAd in InterstitialAd is similar to that in invoking an AdView.

• Import com.umobi.android.ad

• declare for the living example of InterstitialAd

• complete the creation

• upload ads

import com.umobi.android.ad.*;
 
public class BannerExample extends Activity {
 
      private InterstitialAd interstitial;
 
      @Override
      public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.main);
 
              // Create interstitialAd.
              interstitial = new InterstitialAd(this, AdSize.HALF_SCREEN_FLAG);
 
               // Create request for ads
              AdRequest adRequest = new AdRequest();
       adRequest.setPub("pub@channel");
                // Start uploading interstitialAd
                interstitial.loadAd(adRequest);
 
      }
 
      // nvoke displayInterstitial() when you are ready for demonstrating InterstitialAd 
      public void displayInterstitial() {
              if (interstitial.isLoaded()) {
                    interstitial.show();
              }
        }
}

AdSize: you can choose to use half screen flag or full screen flag.

AdSize.HALF_SCREEN_FLAG Half Screen ads
AdSize.FULL_SCREEN_FLAG Full screen ads

The above example may use displayInterstitial to present Ads, however, UC Union recommend you use AdListener to call back Ads demonstration. When InterstitalAd is opened successfully, presented ads will cover full screen of the application window until it is shut down by user.

interstitial.setAdListener(new AdListener(){
    @Override
    public void onAdLoaded(){
       intertitialAd.show();
       //other code in here.
    }
  @Override
public void onBackPressed() {
        intertitialAd.hide();
  }

});

If you use InterstitialAd module, in order to control displaying issues in InterstitialAd, you are required to add the code below in the main Activity.


  @Override
  public void onDesctory(){
    intertitialAd.hide();
    //other code in here.
  }
  @Override
  public void onPause() {
    intertitialAd.hide();
  }

5. APP WALL

API for APP WALL

UC Union supports APP WALL in SDK. To easily present APP WALL in your Android APP with our code, you are required to import com.umobi.android.ad.CurtainAd in your code.

Adding com.umobi.android.ad.CurtainAd

• Import com.umobi.android.ad.*

• Create button or URL for APP WALL entrance in your APP

• Invoke Static’s quickShow, which is provided by CurtainAd.

CurtainAd.quickShow(Activity activity, String pub );

APP WALL can be triggered according to different buttons in your APP.

The code below would make UC Union APP WALL open when users click Button.

Button curtainButton = new Button(this);
curtainButton.setOnClickListener(new View.OnClickListener(){
    public void onClick(View v){
        CurtainAd.quickShow(MyActivity.this,"pub@channel");
    }
});

How to create an APP Wall Assistive Icon through CurtainAd (fixed mode)

CurtainAd(Activity, CurtainAdPosition);
CurtainAdPosition Description
LEFT Present on the left of the screen
BOTTOM Present at the bottom of the screen
RIGHT Present on the right side of the screen

Example 1. Create a white Assistive Icon on the right side of the screen

CurtainAd curtainAd = new CurtainAd(this, CurtainAdPosition.RIGHT);
AdRequest cuRequest = new AdRequest();
cuRequest.setPub("pub@channel");
curtainAd.loadAd(cuRequest);

Example 2. Create a green Assistive Icon at the bottom of the screen, and control the icon to display and hide.

CurtainAd curtainAd = new CurtainAd(this, CurtainAdPosition.BOTTOM);
AdRequest cuRequest = new AdRequest();
cuRequest.setPub("pub@channel");
curtainAd.hide(); //hide the button;
curtainAd.setAdListener( new AdListener(){
 @Override
 public void onAdLoaded(){
 curtainAd.show(); //while AD has loaded for show this button;
 //other code in here.
 }
});
curtainAd.loadAd(cuRequest);

Use CurtainAd to create a Assistive-touch-liked drag-able button for APP WALL entrance, and define it as non-fixed mode.

CurtainAd curtainAd = new CurtainAd(this, CurtainAdPosition.BOTTOM, false);

AdRequest cuRequest = new AdRequest();
cuRequest.setPub("demo@pub");

curtainAd.hide(); //hide the button;

curtainAd.setAdListener( new AdListener(){

  @Override
  public void onAdLoaded(){
 
  curtainAd.show(); //while AD has loaded for show this button;
  
  //other code in here.
  }
});

curtainAd.loadAd(cuRequest);

If you use CurtainAd module, in order to control displaying issues in CurtainAd, you are required to add the code below in the main Activity.

  @Override
  public void onDesctory(){ 
  if (null != curtainAd){
  curtainAd.hide();
  }
  }
  @Override
  public void onPause(){ 
  if (null != curtainAd){
  curtainAd.hide();
  }
  }
  @Override
  public void onResume(){
  if (null != curtainAd){
  curtainAd.show();
  }
  }

Integrate one-time entrance MysteriousAd for APP WALL

Our SDK presents a Gift box button (a one-time entrance) on the left-bottom screen.

This would help developers present one-time entrance for APP WALL easier.

Add com.umobi.android.ad.service.MysteriousAdService and com.umobi.android.ad.service.AppwallService in AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="
          package="com.ucweb.union.sdk"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="10"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:name=".MyApplication" android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen">
        <activity android:name="MainActivity"
                  android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name="com.umobi.android.embedbrowser.EmbedBrowserActivity"
                  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode" />
        <receiver android:name="com.umobi.android.ad.util.NetworkStateReceiver">
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            </intent-filter>
        </receiver>
        <service android:name="com.umobi.android.ad.service.CurtainBallService" />
        <service android:name="com.umobi.android.ad.service.MysteriousAdService" />
        <service android:name="com.umobi.android.ad.service.AppwallService" />
    </application>
</manifest>

How to code MysteriousAd in your APP?

public class MainActivity extends Activity{
    
    private MysteriousAd myAd;
     
    @Override
    public void onCreate(Bundle savedInstanceState) {
        AdRequest myRequest = new AdRequest();
        myRequest.setPub("pub@demo");
        myAd = new MysteriousAd(this);
        myAd.loadAd(myRequest);
    }
    @Override
    public void onDestroy(){
        if(null!=myAd){
            myAd.hide();
        }
    }
    @Override
    public void onPause(){
        if(null!=myAd){
            myAd.hide();
        }
    }
    @Override
    public void onResume(){
        if(null!=myAd){
            myAd.show();
        }
    }
}


Integrate customized entrance for APP WALL

Developer can customize the entrance of appwall themselves, to cater style of their app.

1.Add com.umobi.android.ad.service.MysteriousAdService and com.umobi.android.ad.service.AppwallService in AndroidManifest.xml

2.How to code in your APP

public class MainActivity extends Activity{
    
    private MysteriousAd myAd;
     
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
        ImageButton customerButton = (ImageButton)findViewById(R.id.AppButton);
        myAd = MysteriousAd.simpleShow(this, "pub@demo", customerButton);
    }
}