This directory contains the native Android connector used by PocketBuddy to capture UPI/payment notifications and send normalized transaction payloads to the backend.
All commands below are intended to be run from the repository root:
cd "C:\Users\nhnis\Desktop\Amazon Hackon\PocketBuddy\PocketBuddy"The Android Gradle project is isolated inside android/, but repo-root commands are supported with:
.\android\gradlew.bat -p android <task>PocketBuddy/
android/
build.gradle.kts
settings.gradle.kts
gradlew
gradlew.bat
gradle/
local.properties.example
local.properties # local only, ignored by git
connector/
build.gradle.kts
README.md
src/
main/
debug/
test/
tools/
ingest_test_backend/
app/
README.md
requirements.txt
The Gradle module is named :connector.
- Runs a native Android
NotificationListenerService. - Reads UPI/payment app notification text.
- Reads bank SMS notifications surfaced by apps like Google Messages.
- Parses amount, direction, merchant, transaction/reference ID, and capture source.
- Sends structured JSON payloads plus a masked preview to the configured webhook.
- Does not upload full notification or SMS text on the v2 ingest path.
- Adds stable installation-level
deviceId. - Supports optional
userIdand bearer token binding. - Stores failed webhook sends in an encrypted Android Keystore retry queue.
- Includes debug-only ADB test broadcasts.
Install:
- Android Studio
- Android SDK Platform Tools
- A physical Android phone with Developer Options enabled
- USB debugging enabled on the phone
- Python 3.11+ if using the local FastAPI Android test backend
Use Android Studio's bundled JDK in PowerShell:
$env:JAVA_HOME = "C:\Program Files\Android\Android Studio\jbr"
$env:Path = "$env:JAVA_HOME\bin;$env:Path"
java -versionIf adb is not globally available, use:
$ADB = "$env:LOCALAPPDATA\Android\Sdk\platform-tools\adb.exe"Open this folder in Android Studio:
C:\Users\nhnis\Desktop\Amazon Hackon\PocketBuddy\PocketBuddy\android
Do not open only android/connector; open android/ because it is the Gradle root.
After sync, Android Studio should show one module:
connector
Create android/local.properties from the example:
Copy-Item .\android\local.properties.example .\android\local.propertiesAndroid Studio normally adds sdk.dir automatically. If it does not, add this line manually:
sdk.dir=C\:\\Users\\<YOUR_USER>\\AppData\\Local\\Android\\SdkFor USB testing with adb reverse, use:
POCKETBUDDY_WEBHOOK_URL=http://127.0.0.1:8000/api/ingest/notification-v2
POCKETBUDDY_WEBHOOK_TOKEN=
POCKETBUDDY_USER_ID=For a LAN/ngrok backend, replace the URL accordingly:
POCKETBUDDY_WEBHOOK_URL=https://your-ngrok-url.ngrok-free.app/api/ingest/notification-v2android/local.properties is ignored by git.
These values are build-time defaults. The installed APK also has a setup screen where you can change the webhook URL, user ID, and bearer token without rebuilding.
The backend payload and companion frontend contract are documented in:
docs/mobile-ingest-contract.md
From the repo root:
.\android\gradlew.bat -p android :connector:testDebugUnitTest
.\android\gradlew.bat -p android :connector:assembleDebugInstall on the connected phone:
.\android\gradlew.bat -p android :connector:installDebugIf multiple devices are connected, install through ADB after building:
$ADB = "$env:LOCALAPPDATA\Android\Sdk\platform-tools\adb.exe"
$DEVICE = "10BF821N3M0055M"
.\android\gradlew.bat -p android :connector:assembleDebug
& $ADB -s $DEVICE install -r .\android\connector\build\outputs\apk\debug\connector-debug.apkUse this for the hackathon demo artifact when someone needs to install the Android connector manually.
From the repo root:
cd "C:\Users\nhnis\Desktop\Amazon Hackon\PocketBuddy\PocketBuddy"
$env:JAVA_HOME = "C:\Program Files\Android\Android Studio\jbr"
$env:Path = "$env:JAVA_HOME\bin;$env:LOCALAPPDATA\Android\Sdk\platform-tools;$env:Path"
.\android\gradlew.bat -p android :connector:testDebugUnitTest :connector:assembleDebugThe APK is generated at:
android/connector/build/outputs/apk/debug/connector-debug.apk
Suggested demo filename when sharing outside the repo:
PocketBuddy-Connector-demo.apk
This debug APK is suitable for direct sideload testing. Android will show the normal warning for apps installed outside the Play Store. For a production release or Play Store upload, create a proper release signing key and build a signed release APK/AAB instead of sharing the debug APK.
Before sharing the APK, test the exact file once on a phone:
$ADB = "$env:LOCALAPPDATA\Android\Sdk\platform-tools\adb.exe"
$DEVICE = "10BF821N3M0055M"
& $ADB -s $DEVICE install -r .\android\connector\build\outputs\apk\debug\connector-debug.apkOpen notification listener settings:
$ADB = "$env:LOCALAPPDATA\Android\Sdk\platform-tools\adb.exe"
$DEVICE = "10BF821N3M0055M"
& $ADB -s $DEVICE shell am start -a android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGSEnable:
PocketBuddy UPI Listener
Confirm it is enabled:
& $ADB -s $DEVICE shell settings get secure enabled_notification_listenersYou should see:
com.pocketbuddy.connector/com.pocketbuddy.connector.PocketBuddyNotificationListener
Also open the app once from the launcher:
PocketBuddy Connector
In the setup screen, save the connector config shown by the web app's Companion Device page:
Webhook URL
PocketBuddy user ID
Webhook token, if the backend has issued one
On Android 13+, allow notification permission if prompted. This is needed for debug notification tests, not for listening to other app notifications.
This backend is only for Android connector testing. The final project backend can replace it later.
Create and install dependencies:
py -m venv .\android\tools\ingest_test_backend\.venv
.\android\tools\ingest_test_backend\.venv\Scripts\Activate.ps1
py -m pip install -r .\android\tools\ingest_test_backend\requirements.txtRun from the repo root:
uvicorn android.tools.ingest_test_backend.app.main:app --host 0.0.0.0 --port 8000 --reloadHealth check:
Invoke-RestMethod http://127.0.0.1:8000/healthRecent raw events:
Invoke-RestMethod 'http://127.0.0.1:8000/api/ingest/recent?limit=10' | ConvertTo-Json -Depth 10Canonical de-duplicated transactions:
Invoke-RestMethod 'http://127.0.0.1:8000/api/ingest/transactions?limit=10' | ConvertTo-Json -Depth 10Use this flow after the backend is deployed on AWS EC2 or another public server. This is closer to how a normal user would use the connector.
The phone does not need USB after the APK is installed.
Expected architecture:
Phone Wi-Fi/mobile data
-> http://<EC2_PUBLIC_IP>/api/ingest/notification-v2
-> Nginx on EC2
-> FastAPI backend
-> MongoDB Atlas
On the web app:
- Open the deployed site:
http://<EC2_PUBLIC_IP>
- Login or signup.
- Complete onboarding.
- Open Settings -> Companion Device.
- Copy the connector config.
It should look like:
POCKETBUDDY_WEBHOOK_URL=http://<EC2_PUBLIC_IP>/api/ingest/notification-v2
POCKETBUDDY_WEBHOOK_TOKEN=
POCKETBUDDY_USER_ID=<your_user_id>
On the Android app:
- Open
PocketBuddy Connector. - Paste the webhook URL.
- Paste the user ID.
- Leave webhook token empty unless the backend gives you one.
- Tap
Save connector config. - Tap
Open notification access. - Enable PocketBuddy Connector.
- Return to the app and confirm it says
Ready to sync.
Then test from the web app:
- Keep the backend running on EC2.
- Send a real UPI debit/SMS notification, or use a debug build test broadcast.
- Open Settings -> Companion Device.
- Tap
Check For Real Sync. - Confirm the event appears in Recent Sync Activity and the transaction appears on the dashboard.
Use USB-only commands like adb reverse only for local laptop testing. They are not needed when using the EC2 public URL.
For a USB-connected physical phone, reverse device port 8000 to laptop port 8000:
$ADB = "$env:LOCALAPPDATA\Android\Sdk\platform-tools\adb.exe"
$DEVICE = "10BF821N3M0055M"
& $ADB -s $DEVICE reverse tcp:8000 tcp:8000
& $ADB -s $DEVICE reverse --listExpected:
UsbFfs tcp:8000 tcp:8000
With adb reverse, Android can post to:
http://127.0.0.1:8000/api/ingest/notification-v2
These work only in debug builds.
Direct webhook SMS-style test:
$ADB = "$env:LOCALAPPDATA\Android\Sdk\platform-tools\adb.exe"
$DEVICE = "10BF821N3M0055M"
& $ADB -s $DEVICE shell am broadcast --receiver-foreground -n com.pocketbuddy.connector/.debug.DebugNotificationReceiver -a com.pocketbuddy.connector.DEBUG_UPI_NOTIFICATION --es mode sms --es amount 131 --es merchant CampusCanteen --es transactionId UTR131 --ez directWebhook trueCheck backend:
Invoke-RestMethod 'http://127.0.0.1:8000/api/ingest/recent?limit=5' | ConvertTo-Json -Depth 10Notification-listener path test:
& $ADB -s $DEVICE shell am broadcast --receiver-foreground -n com.pocketbuddy.connector/.debug.DebugNotificationReceiver -a com.pocketbuddy.connector.DEBUG_UPI_NOTIFICATION --es mode sms --es amount 132 --es merchant CampusCanteen --es transactionId UTR132For this path, app notifications must be enabled because the debug receiver posts a local notification that the listener then observes.
- Start the FastAPI test backend.
- Run
adb reverse. - Install the latest debug APK.
- Enable notification listener access.
- Keep logcat open:
$ADB = "$env:LOCALAPPDATA\Android\Sdk\platform-tools\adb.exe"
$DEVICE = "10BF821N3M0055M"
& $ADB -s $DEVICE logcat -c
& $ADB -s $DEVICE logcat -s PocketBuddyListener PocketBuddyWebhook PocketBuddyRetry PocketBuddyRetryQueue- Make a small UPI transaction or wait for a bank SMS.
- Check backend:
Invoke-RestMethod 'http://127.0.0.1:8000/api/ingest/transactions?limit=10' | ConvertTo-Json -Depth 10Expected v2 payload fields:
{
"packageName": "com.google.android.apps.messaging",
"captureSource": "sms_notification",
"deviceId": "installation-scoped-uuid",
"amount": 2.0,
"currency": "INR",
"direction": "credit",
"merchant": "KANIKA SINGHAL",
"transactionId": "208403881695",
"maskedPreview": "Received Rs.2.00 from KANIKA SINGHAL. UPI ref no. [ref]",
"parserVersion": "android-upi-v2",
"confidence": "high",
"rawTextSuppressed": true,
"schemaVersion": 2
}Payment-app notifications are parsed when they expose readable notification text containing:
- INR amount, such as
Rs.50,INR 50, or a rupee symbol amount - UPI/payment signal, such as
UPI,VPA,UTR,txn id, orref no - debit/credit direction, such as
paid,sent,debited,received, orcredited, when available
Known package coverage includes:
- Google Pay
- PhonePe
- Paytm
- BHIM
- Amazon Pay through Amazon Shopping
- WhatsApp payment notifications
- Kotak, Axis, ICICI, HDFC, SBI, PayZapp, CRED, MobiKwik, Freecharge, Airtel, Jio, and common bank/payment package fragments
SMS notification coverage includes:
- Google Messages
- Vivo/Android Messages
- Samsung Messages
- common
messaging,mms, andsmspackage fragments
If a supported payment-like alert has an amount and UPI/reference context but no clear debit/credit direction, the connector sends a low-confidence v2 event with the masked preview so the backend can show it as incomplete review activity instead of silently dropping it. OTP and promotional messages are intentionally rejected.
Check connected devices:
& $ADB devices -lIf device shows unauthorized, unlock the phone and approve the USB debugging prompt.
If device shows offline:
& $ADB reconnect offlineIf adb is not recognized, use:
$ADB = "$env:LOCALAPPDATA\Android\Sdk\platform-tools\adb.exe"If backend is not reachable from phone, run:
& $ADB -s $DEVICE reverse tcp:8000 tcp:8000If Gradle cannot find Java, set:
$env:JAVA_HOME = "C:\Program Files\Android\Android Studio\jbr"
$env:Path = "$env:JAVA_HOME\bin;$env:Path"If build output is stale:
.\android\gradlew.bat -p android :connector:clean
.\android\gradlew.bat -p android :connector:assembleDebugIf no real events appear, verify:
- backend is running on port
8000 adb reverseis active for the selected device- notification listener access is enabled
- the latest APK is installed
- the source notification contains an amount plus UPI/payment signal
- the connector diagnostics show
/api/ingest/notification-v2
android/connector/src/main/java/com/pocketbuddy/connector/PocketBuddyNotificationListener.kt
android/connector/src/main/java/com/pocketbuddy/connector/config/ConnectorConfigStore.kt
android/connector/src/main/java/com/pocketbuddy/connector/parser/UpiNotificationParser.kt
android/connector/src/main/java/com/pocketbuddy/connector/network/WebhookClient.kt
android/connector/src/main/java/com/pocketbuddy/connector/retry/WebhookRetryQueue.kt
android/connector/src/debug/java/com/pocketbuddy/connector/debug/DebugNotificationReceiver.kt
android/tools/ingest_test_backend/app/main.py
docs/mobile-ingest-contract.md