Skip to content

chattylabs/android-sdk-notifications-parser

Repository files navigation

Notifications Parser Component

Build Status Latest version

Android SDK that allows you to retrieve the current active chattylabs.notifications and let you listen for incoming new ones.

demo-sample

Why choosing this SDK?

The Notifications Parser Component SDK contains built-in model algorithms that parse and extract the principal information from several instant messages apps and other installed apps.

It aims to deliver a reliable solution easy to integrate in a project, that measures and takes care of aspects like the order of the incoming chattylabs.notifications, avoiding duplicated items, handling any required permission, reducing battery consumption processes, and providing a simplified API interface among others.

The current built-in models are:

  • WhatsApp
  • Facebook Messenger
  • Telegram
  • Line
  • WeChat
  • Spotify
  • Netflix

Click to learn more about built-in models

By default, if there is no model for the notification, it will return a NotificationData object that contains all the extracted information.

Prerequisites

  • The SDK works on Android version 5.0 (Lollipop) and above. (for lower versions contact us)
  • You need to setup an APP_ID key on ChattyLabs Developer site.

Setup

Add the following code to your gradle file.

repositories {
    maven { url "https://dl.bintray.com/chattylabs/maven" }
}
 
// Optional
android {
    defaultConfig {
        manifestPlaceholders = [CHATTYLABS_APP_ID: "##GENERATED_UUID_NUMBER##"]
    }
}
 
dependencies {
    implementation 'com.chattylabs.sdk.android:chattylabs.notifications-parser:x.y.z'
}

Add the following line inside the <application /> tag of your AndroidManifest.xml

<meta-data android:name="com.chattylabs.sdk.APP_ID" android:value="${CHATTYLABS_APP_ID}" />

Usage

In order to get the chattylabs.notifications objects on your project, you have to create an IntentService class where you can extract the items from the intent extras bundle.

public class NotificationListenerIntentService extends IntentService {
    
    public NotificationListenerIntentService() {
        super("NotificationListenerIntentService");
    }
    
    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
        // Avoid empty intents
        if (intent == null || intent.getAction() == null || intent.getExtras() == null) return;
        
        // Initializes and provides a NotificationParser instance
        NotificationParser NotificationParser =
            NotificationParserModule.provideNotificationParser();
        
        // Extracts the current notification item from the intent extras bundle
        NotificationItem item = NotificationParser.extract(intent);
        
        // ...
    }
}

Remember to register your IntentService class inside your AndroidManifest.xml and to add the various actions you want to receive.

<service android:name="com.example.NotificationListenerIntentService"
    android:exported="false">
    
    <intent-filter>
        <action android:name="com.chattylabs.sdk.android.chattylabs.notifications.action.POST"/>
        <action android:name="com.chattylabs.sdk.android.chattylabs.notifications.action.REMOVE"/>
        
        ...
        
    </intent-filter>
    
</service>

Usage with dependency injection

If you make use of Dagger 2 in your project, you may provide the NotificationParser instance with the @Inject annotation.

public class NotificationListenerIntentService extends DaggerIntentService {
    
    @Inject NotificationParser NotificationParser;
    
    // ...
}

You will need to add NotificationParserModule.class as a module element into your Dagger Component graph. Take a look on how DemoApplication is handling this.

Demo

After you have cloned this demo project, run the following command on a terminal console. This will get and update the project's build system.

git submodule update --init

Projects

This is a list of Apps using the SDK in their project:

Chatty     

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages