Notifications Summarizer Agent (Android)

Platform Language

The agent fetches device notifications, processes them using on-device LLMs, and generates summaries that can be retrieved by the host app. It can operate in the background, at your scheduled timings and is designed to be privacy-centric by keeping all data on the device.

Table of Contents

Quick Setup

  1. Installation Add the agent dependency to your app’s build.gradle.kts or build.gradle file:

    dependencies {
        implementation("dev.deliteai.agents:notification_summarizer:x.x.x") 
    }
    
  2. Initialize NimbleNet Core (Crucial) It is critical to initialize the NimbleNet core library from your Application class. This must be done before any agent can be used.

    In your Application.kt:

    import dev.deliteai.NimbleNet
    import dev.deliteai.datamodels.NimbleNetConfig
    import android.app.Application
    
    class YourApp : Application() {
        override fun onCreate() {
            super.onCreate()
    
            val nimbleConfig = NimbleNetConfig(
                // ... your configuration ...
            )
    
            NimbleNet.initialize(this, nimbleConfig)
        }
    }
    
  3. Add Permissions to Manifest Add the following permissions to your AndroidManifest.xml. These are required because they involve user interaction that the host application must initiate.

    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
    
  4. Initialize the Agent After NimbleNet is initialized, you can initialize the NotificationsSummarizerAgent.

    val config = NotificationSummarizerConfig(
        onScheduledSummaryReady = { notificationSummary ->
            // Handle the summary when the scheduled job completes
        }
    )
    NotificationsSummarizerAgent.initialize(application, config)
    
  5. Get a Summary Request a summary of the current notifications.

    val result = NotificationsSummarizerAgent.getSummaryOfCurrentNotification()
    

Permissions

The SDK’s manifest automatically merges most required permissions and components into your app. However, you are still required to declare and handle permissions that require explicit user interaction.

Manifest Declarations

You must declare the following permissions in your AndroidManifest.xml:

  • POST_NOTIFICATIONS: Allows the agent to post the final summary as a notification. (Runtime request needed on API 33+)

  • SCHEDULE_EXACT_ALARM: Required to schedule the summarization jobs at precise times. (Runtime request may be needed on API 31+)

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

Runtime Requests

Some permissions must be granted by the user while the app is running.

  1. Notification Access: This special permission requires the user to manually enable it in system settings. You should direct the user to this screen.

    val intent = Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)
    startActivity(intent)
    
  2. Post Notifications: On Android 13 (API 33) and higher, you must request this permission to post notifications.

    // Using ActivityResultContracts.RequestPermission()
    requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
    
  3. Exact Alarms: On Android 12 (API 31) and higher, apps need this permission to schedule exact alarms. If it’s not granted, you must redirect the user to system settings.

    val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
    if (!alarmManager.canScheduleExactAlarms()) {
        val intent = Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM)
        startActivity(intent)
    }
    

API Reference

NotificationsSummarizerAgent Methods

  • initialize(application, config) - Initialize agent

  • scheduleNotificationSummaryJob(timeInMillis) - Schedules a job to run at the specified time. When the job executes, it takes a snapshot of the current notifications, generates a summary, and stores it in the local Room database for later retrieval.

  • getSummaryOfCurrentNotification() - Get current summary

  • getSummary(id) - Get summary by ID

  • getSummary(date) - Get summaries for date

  • getSummary(startDate, endDate) - Get summaries in range

NotificationSummary Data Class

data class NotificationSummary(
    val id: String,
    val date: LocalDate,
    val body: String
)