Smart notifications SDK for Android devices
To review all the available methods exposed by the SDK you could check: Javadoc
Add a new repository source to your project level build.gradle:
maven {
url 'http://snip-dev.tid.es/artifactory/snip-sdk-android'
}
This is an example of the final result:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url 'http://snip-dev.tid.es/artifactory/snip-sdk-android'
}
}
}
Edit your app level build.gradle and add the neccessary dependencies:
implementation 'com.telefonica.snlib:SNlib:1.7.+'
implementation 'com.telefonica.snlib:SNlibClassifier:1.7.+'
implementation 'com.telefonica.snlib:SNlibCommons:1.7.+'
implementation 'com.telefonica.snlib:SNlibSensors:1.7.+'
implementation 'com.telefonica.snlib:SNlibPushNotifications:1.7.+'
implementation 'com.google.android.gms:play-services-gcm:11.8.0'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
implementation 'com.android.support:support-compat:26.1.0'
implementation 'com.android.support:support-core-utils:26.1.0'
This is an example of the final result:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.telefonica.snlibintegrationtestapp"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.telefonica.snlib:SNlib:1.7.+'
implementation 'com.telefonica.snlib:SNlibClassifier:1.7.+'
implementation 'com.telefonica.snlib:SNlibCommons:1.7.+'
implementation 'com.telefonica.snlib:SNlibSensors:1.7.+'
implementation 'com.telefonica.snlib:SNlibPushNotifications:1.7.+'
implementation 'com.google.android.gms:play-services-gcm:11.8.0'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
implementation 'com.android.support:support-compat:26.1.0'
implementation 'com.android.support:support-core-utils:26.1.0'
}
You need to select the small icon that the notifications enqueued through our system are going to show. To do this just add a meta-data tag to your app manifest (inside your <application>
tag) with the drawable resource to use:
<meta-data android:name="smart_notifications_icon" android:resource="@drawable/notification">
</meta-data>
In the same way you can also choose the large icon to show:
<meta-data android:name="smart_notifications_large_icon" android:resource="@drawable/notification_large">
</meta-data>
Only once the SDK is started, it will begin to process push notifications and user information. Please ensure you have the necessary user consent — if required by the regulation authorities — before starting the SDK.
You start the SDK by running the method static void initialize(Application application, String licenseToken)
from your app’s Application class with the Application instance and license token associated to your app package that we sent you.
In case your app doesn’t implement a custom Application class you need to create one. Just add a new class to your project that extends android.app.Application
. Example implementation:
And then set the name in your app’s AndroidManifest.xml:
You need to set in the SDK the unique identifier you use in the app for the user of the app (for example the email, UUID or whatever identifier you use for your users). For that you need to call the method static void setUserId(Context context, String clientUserId)
:
The method we use to specify in our push notifications what to do when they are clicked is a URL. If you want that URL to open web content in the phone’s browser you can skip this part, but if you want your push notifications to open specific content in one of your app’s activities you need to configure deep linking in your app.
To do so, you can just follow Google’s tutorial: Create Deep Links to App Content
If this is your case, you need to add two more methods calls in your implementations of the Firebase services.
You need to follow the instructions here: Integrate Firebase in your Android app so your app is correctly configured to work with Firebase