Logo

Android

Android #

To integrate with Android using Java, a framework library with its corresponding set of controls & classes is provided.

For additional information regarding how to reference this library from your Android project, please see the section Library Reference in this document.

Note: In the case where server’s connection isn’t SSL with HTTPS, application permissions should be modified accordingly, see section Connectivity permissions.

Download library

Initialization #

When the application is initialized, the static method load from the class Client should be invoked only one time as shown below. This requires the importation of the module Prisma.


import com.prismacampaigns.sdk.*;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
...
    Client prisma = Client.load(getApplication(), "server", "443", 
                               "22dae0ad-a6a8-4767-80bc-b29098147813", 
                               "1234", "https");

It is recommended to do this initialization when the application main activity finishes loading.

The Client class is a singleton, so any time it’s referenced you will get the same instance of the object, which should be accessed using the static attribute shared.

Client.shared

Initialization parameters for Prisma client library are:

 load(String server, String port, String appToken, String customer, String proto)

:param String server: Server address where Prisma server is running.
:param String port: Access port for the Prisma service.
:param String appToken: Access token for the integrated application.
:param String customer: Identified customer if available, otherwise pass "".
:param String proto: Connection protocol to use, default is "https"

Embedded Banners #

To integrate a banner into an Android View, there is a control named Placeholder, which will be used to dynamically load content.

The following steps should be followed:

  1. Add the control Placeholder from sdk Prisma to the activity layout
<com.prismacampaigns.sdk.Placeholder
android:id="@+id/PHMain"
android:layout_width="800px"
android:layout_height="600px"
android:visibility="visible"
custom:name="PHName">

</com.prismacampaigns.sdk.Placeholder>

In this example, a fixed size placeholder is defined, which will be integrated with the placeholder defined on the campaign manager platform under name PHName.

In each activity you can add as many placeholders deemed necessary.

  1. Force campaigns synchronization when the View is created.
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    ...
    Placeholder pt =  (Placeholder) findViewById(R.id.PHMain);
    Client s = Client.shared;
    List<Placeholder> placeholders = new LinkedList<Placeholder>();
    phs.add(pt);
    s.syncView(this, placeholders,null);

In this case the parameter placeholders passes the list of defined placeholders as activity outlets, and the parameter this refers to the current activity.

Customized Banners #

In case you would like to create banners from your own application code without using the embedded controls provided by our SDK, it is possible with the parameter SyncedHandler of the method syncView.

In such a context, when banners for the synchronized activity are retrieved, the OnSynced callback will be called:

s.syncView("androidview", phs, new SyncedHandler() {
@Override
public void OnSynced(Map<String, PlaceholderContent> result) {
    PlaceholderContent content = result.get("PHName");
    if (content != null) {
        Log.i("MainApp", String.format("Total banners found %s", content.banners.size()));
    }
}
});

To retrieve banner views based on placeholder’s content:

IBanner banner = content.banners.get(0);
View v = banner.getView(pt.getContext());

To obtain the content of an HTML banner:

IBanner banner = content.banners.get(0);
String content = ((HtmlBannerView)banner).getHTMLContent()

To invoke funnel initialization from an existing banner:

banner.getFunnel().start(pt.getContext())

To dismiss a campaign from an existing banner:

banner.getFunnel().dismiss()

Library Reference #

Import the library app-release.aar according the following images:

add_library select_library

Add a reference to gradle as follows:

 dependencies {
    ...
    implementation('us.bpsm:edn-java:0.5.0')
    compile project(":prisma-release")
     ...

}

When you are ready, save the file and synchronize Gradle.

Connectivity Permissions #

Network access permissions should be added to the file AndroidManifest.xml as shown below:

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

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