Push Notification – Infobip Push – Tutorial

Push notifications are a popular form of informing users about new products, promotions, offers, and any messages which we would like to convey to our customers. Their implementation isint easiest thing but we can make it in quicj time if we use platforms such as infobip push.

 

The service is available at https://push.infobip.com For small applications, the service is completely free allowing us to create 3 applications and send 10000 notification. Unfortunately, with larger group of consumers we will have to pay 75 € or 300 € depending on the version which we choose.
 
At the beginning we create our account. As always we give our login name, password and email address. Unfortunately, in order to fully benefit from infobip push we will later need to give our phone number for verification.
 
After logging we will get access to our panel. We create a new application. We give the name of the application, its description, and possibly image. In order to make it work properly we need Google Cloud Messaging API number (API key (GCM)). Google Cloud Messaging, however, recently turned on Firebase Cloud Messaging. So to get an API key we have to go under https://console.firebase.google.com/
 
p2
 
p4
 
There we are registering ourr project giving his name. In the panel we go to Project Settings -> Cloud Messaging and copy the server key and paste it into the InfoBip Push panel. The next step is to implement solutions in the application.
 
p5
 
Download libary https://push.infobip.com/downloads/infobip-push-2.0.1.aar run android studio and create a new project, the minimum version of the android is 15. import into the project just downloaded library File-> New -> New module -> Import .JAR/.AAR package
 
In addition, the library that we need are google play, Retrofit, Gson, ReactiveX. Add all dependencies to Gradle file.
 

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "com.testpush"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile project(':infobip-push-2.0.1')

    compile 'com.android.support:support-v13:24.0.0'
    compile 'com.android.support:appcompat-v7:24.+'
    compile 'com.google.android.gms:play-services:6.1.+'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.okhttp:okhttp:2.0.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'io.reactivex:rxjava:1.0.10'
    compile 'io.reactivex:rxandroid:0.24.0'

    compile 'com.github.oxo42:stateless4j:2.5.0'
}

Go to the file AndroidManifest.xml add here all the necessary permissions to connect to the internet and receive a push notification. With push notification we must specify the name of our package as shown in file below. We can not forget about the Services, BrodcasReciverers and meta tag that indicates the version of the google playlibrary. If we want to send our messages with media, we must add the appropriate activity and set hardwareAccelerated=”true”.
 

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



    <uses-permission android:name="com.testpush.permission.C2D_MESSAGE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <permission
        android:name="com.testpush.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name="com.infobip.push.PushActionService"/>
        <service android:name="com.infobip.push.GcmService"/>

        <receiver android:name="com.infobip.push.GcmReceiver"
            android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE"/>

                <category android:name="com.testpush"/>
            </intent-filter>
        </receiver>
        <receiver android:name="com.infobip.push.PushActionReceiver"/>
        <receiver
            android:name="com.infobip.push.ConsistencyAlarmReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
            </intent-filter>
        </receiver>

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity
            android:name="com.infobip.push.activities.MediaActivity"
            android:hardwareAccelerated="true"
            android:screenOrientation="portrait">
        </activity>

        <activity
            android:name="com.testpush.MediaActivity"
            android:label="@string/title_activity_media" >
        </activity>
    </application>

</manifest>

This leaves us to implement the code for the application, presenting it as follows:
 

package com.testpush;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.infobip.push.Configuration;
import com.infobip.push.Notification;
import com.infobip.push.PushClient;
import com.infobip.push.activities.MediaActivity;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        Configuration pushLibraryConfiguration =
                Configuration.customConfiguration(getApplication())
                        .applicationId("0iedbanus3w4")                //Numer identyfikacyjny aplikacje "
Application ID" znajdujący sie w panelu ibnfobip
                        .applicationSecret("4lqwcrq4l5nzlv9")           //"Application secret" wygenerowany przez aplikacje znajdujący się również w panelu infoBip
                        .projectNumber("761011732022")  //Numer Id aplikacji możemy ją znaleźć w panelu FCM obok server key (Sender id)
                        .production(false)
                        .build();
        PushClient.configure(getApplication(), pushLibraryConfiguration);
        PushClient.start();

//Tworzenie nowej aktywności w której odbieramy media wysłane z panelu infobip

        Intent onMediaNotificationClickIntent = new Intent(getApplicationContext(), MediaActivity.class);
        Notification.DefaultNotificationHandler.onNotificationClickIntent(
                onMediaNotificationClickIntent,
                Notification.DefaultNotificationHandler.NotificationType.media

        );

    }

}
public class MediaActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String jsonData = getIntent().getExtras().getString(
                Notification.DefaultNotificationHandler.INTENT_EXTRAS_KEY
        );
    }
}

In InfoBip panel we can set the message subject, brief information about the message and the content of the message being sent as follows:
 
p6
 
p7
 
p8
 
When we send notifications it will appear to us here as such result:

and1img2

 
InfoBip allows for quick and easy messaging. In addition, it is possible to identify grouping and identifying individual users. Send messages to people in the selected region of the world or to respond to events such as message delivery, clicking on the message. In order to gain more information refer to the relevant documentation https://push.infobip.com/docs/platforms/android#androidLibrary

One thought on “Push Notification – Infobip Push – Tutorial

Leave a Comment

WordPress Video Lightbox Plugin