The Netmera Developer Hub

Welcome to the Netmera developer hub. You'll find comprehensive guides and documentation to help you start working with Netmera as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

Netmera Push Notification

Netmera Push Notification is a service that enables developers to send push notifications and data with the notification to their applications. It is developed on the top of Google Cloud Messaging (GCM), so that it works with the Android 2.2 and later versions.

Step 1 - Creating Project in Google Api Console for GCM

You should get Project Number and API key from the Google and also you should enable the GCM Service. In order to complete these requirements; first open the Google APIs Console page from the link below.
https://console.developers.google.com/project

If you haven’t created an API project yet, the page will prompt you to do so.

In Overview page of the project, you can see your project’s number. It is like Project Number: 65320729210. Take note of this value. This is your project number, and it will be used later on while registering devices.

After creation of your project, you need to enable Google Cloud Messaging for Android service. From the left menu, open your project page. Select APIs & auth -> APIs and turn the Google Cloud Messaging for Android toggle to ON and accept the terms in the Terms of Service page.

Lastly you should obtain an API key. To obtain an API key, in the main Google APIs Console page, select APIs & auth -> Credentials. You will see a screen that resembles the following:

Click Create new Key:

Click Server key:

Click Create. After creation of API key, you will see a screen that resembles the following.

Take note of the API key value.

Step 2 - Saving Google API Key in Netmera Panel

You should save your Google API Key into the Android API Key part of application’s settings page shown in the image below.

Step 3 - AndroidManifest.xml File and Gradle Operations

IMPORTANT NOTE:

Netmera requires two dependencies for push notifications which could be found below. You should add below code to your build.gradle file. It is recommended to use current play-services-version

compile 'com.google.android.gms:play-services-gcm:{play-services-version} '
compile 'com.google.android.gms:play-services-ads:{play-services-version} '

In order to create Android application, you must add the following configurations into the AndroidManifest.xml file.

Since our service uses Google Cloud Messaging (GCM) in background, it works with the Android 2.3 and later versions. So, if your application does not work, add the following line. In the following line, xx stands for the latest SDK version.

<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="xx"/>

Following permissions must be defined in order to use Netmera Push service.

<!-- Used to connect Netmera Services -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- Push Notification requires Google Account -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

<!-- This permission is needed to register and receive message -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<!-- Create custom permission so only this app can receive its messages.
        Note that permission should be started with the package name. 
        packageName.permission.C2D_MESSAGE -->
<permission android:name="YOUR_APP_PACKAGE.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="YOUR_APP_PACKAGE.permission.C2D_MESSAGE" />

Add the following BroadcastReceiver between the application tag placed in AndroidManifest.xml file. Note that, YOUR_APP_PACKAGE field in the category tag must be replaced by your application’s package name.

<receiver android:name="com.netmera.mobile.NetmeraBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <category android:name="YOUR_APP_PACKAGE" /> 
    </intent-filter> 
</receiver>

You should add the following configuration for IntentService. This service is used to handle registration and sending notifications.

<service android:name="com.netmera.mobile.NetmeraIntentService" />

Android Push Icon

Push Icon (RECOMMENDED)

It is recommended to use a push notification icon that is monochromatic and flat. Default push icon is your app icon and mostly it doesn’t conform to the Android style guide. You can set your custom icon from AndroidManifest.xml file of your project. Just add the following metadata tag to your app’s AndroidManifest.xml under application tag.

<meta-data android:name="com.netmera.mobile.push_icon" android:resource="@drawable/custom_push_icon" />

where custom_push_icon is the name of a drawable resource in your package.

Push Icon Background (RECOMMENDED)

NOTE: Please be sure that you are using Netmera Android SDK version 2.9.3+ for this feature

If you want to change background of the push notification icon, Just add the following metadata tag to your app’s AndroidManifest.xml under application tag. You should also use monochromatic and flat icon for the compatibility with Android 5.0+ Below code could be used to change background of the push notification icon.

<meta-data android:name="com.netmera.mobile.push_color" android:value="#f47f1f" />

Step 4 - Registering Device and Initial Steps

Registering Device
By adding the following code in onCreate() method, you can register applications to receive notification.

NOTE

1- If you added Google project number and push activity class to your netmera.properties file, you don’t need to call this register method without user tags and custom fields. In this case, push registration will be done by Netmera automatically.

2- Instead of netmera.properties file, If you called Netmera.init method in your Application class with NetmeraProperties object as a parameter, you also don't need to call this register method without user tags and custom fields.

Probable Usage Scenario of this method: If you unregister device from push notification service and later registering this device again

// Firstly, you should initialize Netmera to be able to use Netmera services. See Android Guide main page for more details.

/* Register method has three parameters. 
applicationContext : current application context.
activityClass : This is the activity which should NetmeraActivity launched when user clickes on the notification. 
You can register with a class which does not extend NetmeraActivity. In such a case, you need to add event methods to your Push Activity's onCreate method. 
projectID : This is the ID that you get from the Google on the step-1.*/ 
try { 
    NetmeraPushService.register(applicationContext, projectId, activityClass); 
} catch (NetmeraException e) { 
    // Handle exception 
}

Registering Device with Tags

If you want to register different tags; you can register these tags by using NetmeraDeviceDetail object.

NetmeraDeviceDetail deviceDetail = new NetmeraDeviceDetail(applicationContext, projectId, activityClass);
List<String> tags= new ArrayList<String>();
tags.add("News");
tags.add("Sports");
deviceDetail.setTags(tags);
try {
    NetmeraPushService.register(deviceDetail);
} catch (NetmeraException e) {
    // Handle exception
}

If device tags of NetmeraDeviceDetail object are not set; the device is only registered to BROADCAST tag.

NOTE

If there is already registered tags and the device is again registered to different tags, these tags will be added to the previous registered tags.

Example:

deviceDetail.addTag("Tech");
try {
    NetmeraPushService.register(deviceDetail);
} catch (NetmeraException e) {
    // Handle exception
}

Now, the device is registered to Sports, News and also Tech tags.

Registering with Custom Fields

You can also set custom key-value pairs over NetmeraDeviceDetail object when registering a device. Therefore, if a push notification is sent for the specific custom field(s), the devices registered to them should automatically receive the message. The developers should be aware of the fact that every time a device is registered with custom field(s), new key-value pair(s) overrides the current ones.

PS: You can set both custom fields and tags on NetmeraDeviceDetail object while registering.

NetmeraDeviceDetail deviceDetail = new NetmeraDeviceDetail(applicationContext, projectId, activityClass);
Map<String, Object> customFields = new HashMap<String, Object>();
customFields.put("key1", "value1");
customFields.put("key2", "value2");
deviceDetail.setCustomFields(customFields);
try {
	NetmeraPushService.register(deviceDetail);
} catch (NetmeraException e) {
//	Handle exception
}

Registering With Custom Fields Without Overriding

If you want to use current custom fields also(instead of completely overriding them), you should get them from Netmera first. Example is below

NetmeraPushService.getDeviceDetailInBackground(getApplicationContext(), new NetmeraCallback<NetmeraDeviceDetail>() {
            @Override
            public void onSuccess(NetmeraDeviceDetail netmeraDeviceDetail) {
                netmeraDeviceDetail.getCustomFields();  // This is a Map object
                // current custom fields of the device is available now.
                // if you want to use them also, you should follow this pattern
            }

            @Override
            public void onFail(NetmeraException e) {

            }
        });

You can also check whether device is registered or not by using following code.

NetmeraPushService.isRegistered(applicationContext);

You can retrieve GCM registration ID of current user by using the following code.

String regId = NetmeraPushService.getRegistrationId(getApplicationContext());

Unregistering Device from Push Notifications

Complete Unregister from Push Notifications.
You can unregister devices using the following code.
First option:

NetmeraPushService.unregister(applicationContext);

Second option:

NetmeraDeviceDetail deviceDetail = new NetmeraDeviceDetail(applicationContext);
NetmeraPushService.unregister(deviceDetail);

Unregistering Device from Tags

If you want to unregister from different tags; you can unregister by using again NetmeraDeviceDetail objects.

NetmeraDeviceDetail deviceDetail = new NetmeraDeviceDetail( applicationContext );
List<String> tags= new ArrayList<String>();
tags.add("News");
tags.add("Tech");
deviceDetail.setTags(tags);
NetmeraPushService.unregister(deviceDetail);

Example: Before calling this method, lets say device is registered to News, Tech and Sports tags. After calling this method, our device will be unregistered from News and Tech tags and remains only registered to Sports tag.

NOTE

If the device is also unregistered from Sports tag; the device remains as registered to BROADCAST tag even though there is no registered tag left.

There is another important point here; if the tags array is empty at unregistering process, it will also unregister the device from push notifications.

Get Registered Tags of The Device

You can get the device detail and then tags of the registered device using the following code block.

NetmeraPushService.getDeviceDetailInBackground(getApplicationContext(), new NetmeraCallback() {
		@Override
		public void onSuccess(NetmeraDeviceDetail netmeraDeviceDetail) {
			List deviceTags = netmeraDeviceDetail.getTags();

		}

		@Override
		public void onFail(NetmeraException exception) {

		}
});

Get All Tags of All App Users:

The code below is to retrieve all tags of all registered app users.You can get the all tags of all registered devices using the following code.

try {
    List<String> list=NetmeraPushService.getTags();
} catch (NetmeraException e) {
    // Handle Exception
}

Registering Push With Override Flag (Without Unregistration)

After registering a user with tags, you may want to change tags that your user is registered to. You can remove tags by unregistering from them as we explained above. Also, you can override registration tags by setting a flag on NetmeraDeviceDetail class.

We can explain function of override flag with a use case. Let’s say a user is registered to tags Sport and Cars. Something happened and you want to register this user to another tag list Flowers and Birds but removing from existing ones and you don’t want to use unregister function for some reason. So, to override tags with new ones, you need to add the following lines of code when registering. You must set override flag to true. Its default is false.

NetmeraDeviceDetail detail = new NetmeraDeviceDetail(getApplicationContext(), "sender id", YourPushActivity.class);
List<String> tags = new ArrayList<String>();
tags.add("Flowers");
tags.add("Birds");
detail.setTags(tags);
detail.setOverrideTags(true);
try {
	NetmeraPushService.register(detail);
} catch (NetmeraException e) {
	e.printStackTrace();
}

After running this code, the user will be removed from the previous tags and will be registered to new tags Flowers and Birds.

Step 5- Testing Push Notifications Before Sending

NOTE

Please implement this feature in your application. This is very important for marketers which will use Netmera for push notification campaigns.

If you want to add some of your devices to test group and use them for testing push campaigns, you should define following intent filter in one of your activities.

<intent-filter>
    <action android:name="android.intent.action.VIEW" />

    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <!-- Change yoursubdomain with your subdomain of Netmera Application Url -->
    <!-- Suppose your url is cp.netmera.com/greatapp/ -->
    <!-- Then your scheme should be nmgreatapp -->
    <data android:scheme="nmyoursubdomain" />
</intent-filter>

EXAMPLE

You should define this intent filter in one of your application activity. Suppose you have an activity namely MainActivity in your application, so this activity definition looks like this:

<activity android:name=".MainActivity" >
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <!-- Change yoursubdomain with your subdomain of Netmera Application Url -->
        <!-- Suppose your url is cp.netmera.com/greatapp/ -->
        <!-- Then your scheme should be nmgreatapp -->
        <data android:scheme="nmyoursubdomain" />
    </intent-filter>
</activity>

When this activity is opened(for example in onCreate() method, you should call the code below

NetmeraEvent.sendTestGroupEvent(this)

NOTE

It is recommended to create a new activity for this test user feature instead of using MainActivity and you should call the code NetmeraEvent.sendTestGroupEvent(this) in this Activity's onCreate method. Be careful about AndroidManifest.xml file. You should put related intent filter above to the Activity that includes the code NetmeraEvent.sendTestGroupEvent(this)

Lastly, you should add testers from your application Settings Page.

When an e-mail address is added, an e-mail is sent to that user and if the user opens the link inside the mail from app installed mobile device, your specified activity will be opened. When this activity is opened(for example in onCreate() method), you should call NetmeraEvent.sendTestGroupEvent(this) event.
Remember, if the user is not opened the application via the sent mail, the user will not be added to the test group, which means this method does nothing.

Step 6 – Deeplinking Mechanism (New Feature for navigation)

First of all, you should use Netmera Android SDK v_2.9.1 or above in order to navigate user to spesific page in the app using deeplinking mechanism after clicking a push notification. In your AndroidManifest.xml, you should add an intent filter to your Activities which you want to navigate your users after push clicks based on deeplink parameters like below:

<activity android:name=".YourActivity">
 <intent-filter>
 <action android:name="android.intent.action.VIEW"></action>

 <category android:name="android.intent.category.DEFAULT"></category>
 <category android:name="android.intent.category.BROWSABLE"></category>

 <data android:scheme="yourscheme" android:host="yourhost"></data>
 </intent-filter>
</activity>

For example, you can create a deeplink like below(it has two parameters: “productId” and “productCategory”). Parameters should be written in curlybraces( ex: {productCategory} )You can give them meaningful labels which could be easily understood by marketers.

Example Deeplink which is created from Netmera panel:

yourscheme://yourhost?productId={productId}&productCategory={productCategory}

If one of your activity has that scheme and host in AndroidManifest file, that Activity will be opened. You can take the query parameters which is entered from Netmera panel like below: (Note: You should define different host names for each Activity in AndroidManifest.xml file to be sure that there is not any conflict. You can use the Activity name as host name)

String yourDeeplinkParam1= getIntent().getData().getQueryParameter("productId");
String yourDeeplinkParam2= getIntent().getData().getQueryParameter("productCategory");

Usage in Netmera Panel:

Note 1: Please be careful about the issue: ALL of your activities should call NetmeraEvent.onStart(this) in onStart methods and NetmeraEvent.onStop(this) in onStop methods. In addition, if you finish your activities (the ones which have host and scheme in manifest file) in onCreate method of that activity, you should call the code NetmeraEvent.sendPushClickedEvent(getIntent()); before you call finish() method. For more information please visit: Netmera Event Guide page.

Note 2:If you are using custom message parameters previously to navigate your users to a spesific page, don’t worry to use this feature because the system continues to send these custom parameters with push data by converting deeplink parameters to custom parameters additionally. But be sure that your custom message parameters and newly created deeplink query parameters have the same name. This could be important for your users who are not updated your application.

Step 7 - Sending Data With Push Notif. (Other navigation method)

NOTE

If you implemented the navigation structure with deeplinks (Step 6), you can skip this step. It is recommended to use deeplink mechanism because of its flexibility

Payload information as key-value pairs can be sent with the notification by setting values in the Message step of the ‘Push Notification’ screen. Therefore, you can deliver extra information in addition to your notification plain text.

In your activity that you gave when you registered to push service , call the following code block to obtain key-value pairs:

Bundle extras = getIntent().getExtras();
if (extras != null) {
    if(extras.containsKey("YOUR_KEY")){
        String extra = extras.getString("YOUR_KEY");
    }
}

One more thing you must consider is that you should check whether the value exists for the given key or the key that you use is currently available in the payload information, because you can send pair information without value as well as without both key and value.

In addition, you may want to get push message text in your application. In order to get push message text in your activity that you gave when you registered to push service, you should add the following code part.

Bundle extras = getIntent().getExtras();
if (extras != null) {
    if(extras.containsKey(NetmeraIntentService.EXTRA_INCOMING_MESSAGE_TEXT)){
        String pushMessageText = extras.getString(NetmeraIntentService.EXTRA_INCOMING_MESSAGE_TEXT);
        // You can use push message text for your purpose
    }
}

Step 8 – Handling with Rich Push Notifications

“Rich Push Notification” is a feature based on push notification, which gives the developer the choice to send the html-formatted content. Therefore, the developers can send push notifications that contains well-designed html pages to their customers instead of plain-text notifications.After sending push notifications, you should call

NetmeraPushService.handleRichPush (MyRegisteredActivity.this);

method inside your push activity class. This activity class is one of the parameters of your register method and will be opened when the push notification is pressed by the user. If your push notification is a rich one; by calling handleRichPush() method, your rich push content will be loaded and shown to the user, Otherwise, you can check the return value of this method and if the returned value is false; it means this notification is a basic push and you can handle this situation as you want.

try {
    boolean isRich = NetmeraPushService.handleRichPush(MyRegisteredActivity.this);
    if(!isRich){
        // Handle basic push
    }
} catch (NetmeraException e) {
        // Handle exception
}

Alternative Way: Showing Rich Push Content in a Custom Webview

If you want to customize display of Rich push, you should create a WebView for rich push notification and load content in it like below.(It is recommended to make this in your Push Activity class which you provided in Netmera.init method)

Bundle pushExtras = getIntent().getExtras();
if(NetmeraPushService.isRichPush() && pushExtras != null)) {
  String pushId = pushExtras.getString(NetmeraIntentService.EXTRA_NOTIFICATION_NETMERA_ID);
	NetmeraPushService.handleRichPushWithId(yourWebView, pushId);
}

Step 9- Interactive Push Notifications

This feature is supported by Android versions newer than Android 4.1(API Level 16).
You can add interactive buttons to your push notifications and customize them to improve user engagement.
Here is step by step how to add interactive push support.

  • You need to add 2 buttons for an interactive push. These buttons must be under a set and the set must have a unique name. To be able to show the buttons with notifications, Netmera needs icons to be shown near the button. These icons must be under drawable files. You can set button icon name as in the following code sample. For example, if you have an icon named first_button.png, you will set first_button as name. Recommended icon size is 32px*32px for xxhdpi. For others, Android will scale automatically. Remember, if Netmera cannot find any of these icons under drawable folders, notification will not be shown.
  • You need to define an action activity for button set. This activity will be started when any of the buttons is clicked. You can define your action activity same with your push activity. If user doesn’t click any of the buttons and clicks notification directly, your push activity defined when registering will be opened.
  • If you want the button to dismiss the notification and not open the app, you need to set it to true to perform in background as following. Default is false.
builder.performInBackground(true);
NetmeraPushActionButton okButton = new NetmeraPushActionButton.Builder("OK").iconName("ic_ok").performInBackground(false).build();
NetmeraPushActionButton dismissButton = new NetmeraPushActionButton.Builder("Dismiss").iconName("ic_dismiss").performInBackground(true).build();

NetmeraPushActionButtonSet buttonSet = new NetmeraPushActionButtonSet.Builder("Ok-Dismiss").actionActivity(SecondActivity.class).addButton(okButton).addButton(dismissButton).build();

NetmeraPushActionButtonSetList buttonSetList = new NetmeraPushActionButtonSetList.Builder().addNotificationActionButtonSet(buttonSet).build();
NetmeraPushService.savePushActionButtonSetInBackground(buttonSetList, null);

You can set a listener to this request if you want to be informed about the result.

You can add more than one button set to a request. Just build a new button set and add it to button set list using addNotificationActionButton(NetmeraPushActionButtonSet) method of NetmeraPushActionButtonSetList.Builder() before calling NetmeraPushService.savePushActionButtonSetInBackground(buttonSetList, null);

Now you need some small changes in AndroidManifest.xml file of your project.

Remember, we have added a BroadcastReceiver in the beginning of integration. Now, we will update it.

NetmeraBroadcastReceiver needs an action to listen action button clicks. Please add following to the receiver.

<action android:name="com.netmera.mobile.PUSH_ACTION_BUTTON_CLICKED"/>

Your receiver definition will look like this after you add the action.

<receiver android:name="com.netmera.mobile.NetmeraBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >

    <intent-filter>

       <action android:name="com.google.android.c2dm.intent.RECEIVE"/>

       <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

       <!——You need to add this action >

       <action android:name="com.netmera.mobile.PUSH_ACTION_BUTTON_CLICKED"/>

       <category android:name=“YOUR_PACKAGE_NAME” />

   </intent-filter>

</receiver>

Now we are ready to go!
Here is how to send Interactive Push from Netmera control panel step by step.

  • Run the application and save your button set list.
  • Open Netmera Control Panel. Go to Campaigns page and select START AN INTERACTIVE PUSH CAMPAIGN.
  • In 3rd step of campaign creation, set your notification message and then select a Push Category. If you haven’t created one yet, click Create Category below Push Category select box.
  • In Create Category screen, name your category and assign the button set you saved from device before.
  • When you click save, Netmera will redirect you to the notification creation screen.
  • Select your push category. You will see button set tab opened. You can pass parameters to your application or you can open a web page via any of 2 buttons.

Other steps are the same with standard push notification creation.

Push and see!

1- If you send parameters with the button, you can get them using following code line in your Push Activity class:

Bundle extras = getIntent().getExtras();
if (extras != null) {
    String val = extras.getString(“your_key_from_panel”);
    //Do your work
}

2- If you use deeplink instead of message parameters, you can get deeplink parameters like below:

Example Deeplink which is created from Netmera panel:

Example Deeplink

yourscheme://yourhost?productId={productId}&productCategory={productCategory}

If one of your activity has that scheme and host in AndroidManifest file, that Activity will be opened. You can take the query parameters which is entered from Netmera panel like below: (Note: You should define different host names for each Activity in AndroidManifest.xml file to be sure that there is not any conflict. You can use the Activity name as host name)

String yourDeeplinkParam1= getIntent().getData().getQueryParameter("productId");
String yourDeeplinkParam2= getIntent().getData().getQueryParameter("productCategory");

Sending Image With Notification To Notification Bar

This feature is supported by Android versions older than Android 4.1(API Level 16).

You can send image url to be shown in the status bar with your incoming push notifications. You just need to set an image url while sending your notification. In the 3rd step of notification creation screen, add an image url to Large Icon field.

Other steps are the same with standard notification.

Remember, if your Android version is lower than Android 4.1(API Level 16), you will see a standard notification instead notification with picture.

Recommended image size is 1024px width and 512px height for xxhdpi devices. For others, Android will scale automatically.

Step 10- Customized Push Notification Sound and Vibration

You can customize push notification sounds for different push notification messages. To do this, you should add your desired notification sound files under res/raw directory. Notification sound file names must start with “nps_”. File extension for sound files must be midi or mp3.

While sending push notification message, you can see a combo box that contains all of your sounds, you can select one of them to play the sound with notification.

If you want to vibrate the devices when the composed push notification is received, you should add the following permission to your AndroidManifest.xml file.

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

Step 11 – Push Inbox For Rich Push Notifications

“Push Inbox” is a feature, which gives the opportunity to store and redisplay rich push notifications via an interface in your application.

By default, this feature is not included in the SDK. If you want to use Netmera’s push inbox, you should add an external project named as NetmeraPushInbox to your project. You can download it from this page. If you don’t want to add this library project, you have to create an Activity to show incoming rich pushes. In this way, all coming rich push notifications are shown in your own activity which you pass as parameter when registering push. You can simply do it like this:

try {
    boolean isRich = NetmeraPushService.handleRichPush(MyRegisteredActivity.this);
    //handleRichPush(Activity) method handles push message and returns true if the incoming push is rich.
    //If the incoming push is not rich, this method returns false. In this case, you should handle standard pushes
} catch (NetmeraException e) {
        // Handle exception
}

To use Netmera’s push inbox which is in NetmeraPushInbox library project, first you download the project and add your project as shown in the figures below.

After importing NetmeraPushInbox library project it comes to our workspace as NetmeraPushInboxActivity shown below. NetmeraPushInboxTest is our test project to add the library.

After that, you must add the code written below for Activity definition to your AndroidManifest.xml file.

<activity android:name="com.netmera.pushinbox.NetmeraPushInboxActivity"></activity>

In order to enable push inbox feature in your application, simply call enable method like this:

NetmeraPushService.enablePushInbox();

This enable function must be called once. After enabling, no need to call this method again.

In order to disable push inbox feature in your application, you can simply do it like this:

NetmeraPushService.disablePushInbox();

This disable function must be called once. After disabling, no need to call this method again. NetmeraPushInbox will be disabled until you call enable method.

In case you want to open Push Inbox when a custom action occurs (i.e. touch event of a button), you have to create an intent that is responsible to start NetmeraPushInboxActivity. You can simply do it like this:

Intent pushInboxIntent = new Intent(“your application context”, NetmeraPushInboxActivity.class);
startActivity(pushInboxIntent);

NetmeraPushInbox shows the list of rich push notifications that have been sent to your phone. Additionally, all controls and user interface related to push inbox are open source, so that you can change the default ones or use your custom ones if you like. You can find the related source codes under the library project.

You may not want to use Netmera’s Push Inbox. If you want to write your own push inbox code, you can use NetmeraPushInboxDataController class. There are 4 different actions that you can do.

Retrieve User Related Push Notifications

You should think push inbox as a small email inbox. There are notification messages, current user is in target users of these notifications.

To retrieve notifications for current user, you can use the following method.

NetmeraPushInboxDataController.getUserRelatedPushNotifications();

Now, you can create your own push inbox list with this list.
This method will return you a list of NetmeraRichPushObject. There are another method which retrieves notifications in background. If you run the code on the main thread, it will block the application. On Android 3.1 and upper versions, it results with an exception also. So, we recommend you to use background methods over others. Here is an example of this:

NetmeraPushInboxDataController.getUserRelatedPushNotificationsInBackground(new NetmeraCallback<List<NetmeraRichPushObject>>() {
	@Override
	public void onFail(NetmeraException e) {
		// failed
	}
	@Override
	public void onSuccess(List<NetmeraRichPushObject> list) {
		//success
	}
});

Cache mechanism can be used while retrieving user related push notifications. There are five different cache types, namely:
DEFAULT
FROM_CACHE
FROM_NETWORK
FIRST_CACHE_THEN_NETWORK
FIRST_NETWORK_THEN_CACHE

Here is an example usage of retrieving user related notifications with cache option:

NetmeraPushInboxDataController.getUserRelatedPushNotificationsInBackground(CacheType.FIRST_NETWORK_THEN_CACHE, new NetmeraCallback<List<NetmeraRichPushObject>>() {
	@Override
	public void onFail(NetmeraException exception) {
		//	failed		
	}

	@Override
	public void onSuccess(List<NetmeraRichPushObject> result) {
		//	success
	}

});

Deleting Push Notifications From Inbox

User may want to delete push notification from the inbox. To delete notifications, you can use the following method.

try {
	NetmeraPushInboxDataController.markPushAsDeleted("your push notification id to delete");
} catch (NetmeraException e) {
	//unsuccessful due to connection problems
	e.printStackTrace();
}

Parameter of the markPushAsDeleted method is var-args so that you can delete more than one notification with one request.

Marking Notifications as Read

User may want to mark push notification as read in the inbox. To mark it as read, you can use the following method.

try {
	NetmeraPushInboxDataController.markPushAsRead("notification id to mark as read");
} catch (NetmeraException e) {
	//unsuccessful due to connection problems
	e.printStackTrace();
}

Parameter of the markPushAsRead method is var-args so that you can delete more than one notification with one request.

Marking Notifications as Unread

User may want to mark push notification as unread in the inbox. To mark it as unread, you can use the following method.

try {
	NetmeraPushInboxDataController.markPushAsUnread("notification id to mark as unread");
} catch (NetmeraException e) {
	//unsuccessful due to connection problems
	e.printStackTrace();
}

Parameter of the markPushAsUnread method is var-args so that you can delete more than one notification with one request.

Netmera Push Notification