├── CHANGELOG.md ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── feature_request.yaml │ └── bug_report.yaml ├── pull_request_template.md └── workflows │ ├── npmpublish.yml │ ├── stale.yml │ └── helpwanted.yml ├── example ├── .watchmanconfig ├── _node-version ├── .ruby-version ├── consents.ts ├── .editorconfig ├── app.json ├── .bundle │ └── config ├── tsconfig.json ├── .eslintrc ├── babel.config.js ├── android │ ├── app │ │ ├── src │ │ │ ├── main │ │ │ │ ├── res │ │ │ │ │ ├── values │ │ │ │ │ │ ├── strings.xml │ │ │ │ │ │ └── styles.xml │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ └── drawable │ │ │ │ │ │ └── rn_edit_text_material.xml │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ └── MainApplication.java │ │ │ ├── debug │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── ReactNativeFlipper.java │ │ │ └── release │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── ReactNativeFlipper.java │ │ ├── debug.keystore │ │ ├── proguard-rules.pro │ │ ├── google-services.json │ │ └── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── settings.gradle │ ├── build.gradle │ ├── gradle.properties │ ├── gradlew.bat │ └── gradlew ├── .prettierrc ├── .vscode │ └── settings.json ├── Gemfile ├── metro.config.js ├── .gitignore ├── package.json ├── src │ └── App │ │ ├── styles.ts │ │ ├── index.tsx │ │ └── fullScreen.tsx └── index.tsx ├── package ├── .gitattributes ├── .eslintignore ├── .prettierignore ├── .commitlintrc ├── .npmignore ├── .prettierrc ├── .vscode │ └── settings.json ├── index.js ├── android │ ├── gradle.properties │ ├── README.md │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── lesimoes │ │ │ │ └── androidnotificationlistener │ │ │ │ ├── BootUpReceiver.java │ │ │ │ ├── RNGroupedNotification.java │ │ │ │ ├── RNAndroidNotificationListenerPackage.java │ │ │ │ ├── RNAndroidNotificationListenerHeadlessJsTaskService.java │ │ │ │ ├── RNAndroidNotificationListener.java │ │ │ │ ├── RNAndroidNotificationListenerModule.java │ │ │ │ └── RNNotification.java │ │ │ └── AndroidManifest.xml │ └── build.gradle ├── index.d.ts ├── .gitignore ├── LICENSE ├── .eslintrc ├── package.json └── README.md ├── .husky ├── pre-commit └── commit-msg ├── .codacy.yml ├── CONTRIBUTING.md ├── CODE_OF_CONDUCT.md └── README.md /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /example/_node-version: -------------------------------------------------------------------------------- 1 | 16 2 | -------------------------------------------------------------------------------- /example/.ruby-version: -------------------------------------------------------------------------------- 1 | 2.7.6 2 | -------------------------------------------------------------------------------- /package/.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | -------------------------------------------------------------------------------- /package/.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | android/ 3 | .vscode/ -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | -------------------------------------------------------------------------------- /example/consents.ts: -------------------------------------------------------------------------------- 1 | export const API_URL = "" // add api url here -------------------------------------------------------------------------------- /package/.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | android/ 3 | .vscode/ -------------------------------------------------------------------------------- /example/.editorconfig: -------------------------------------------------------------------------------- 1 | # Windows files 2 | [*.bat] 3 | end_of_line = crlf 4 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Query", 3 | "displayName": "Query" 4 | } -------------------------------------------------------------------------------- /package/.commitlintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["@commitlint/config-conventional"] 3 | } -------------------------------------------------------------------------------- /example/.bundle/config: -------------------------------------------------------------------------------- 1 | BUNDLE_PATH: "vendor/bundle" 2 | BUNDLE_FORCE_RUBY_PLATFORM: 1 3 | -------------------------------------------------------------------------------- /example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@tsconfig/react-native/tsconfig.json" 3 | } 4 | -------------------------------------------------------------------------------- /example/.eslintrc: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: '@react-native-community', 4 | }; 5 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | cd package 5 | yarn lint 6 | -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /.codacy.yml: -------------------------------------------------------------------------------- 1 | --- 2 | exclude_paths: 3 | - '.github/**' 4 | - '.vscode/**' 5 | - 'sample/**' 6 | - '**.md' -------------------------------------------------------------------------------- /package/.npmignore: -------------------------------------------------------------------------------- 1 | .codacy.yml 2 | .eslintrc 3 | .gitattributes 4 | .gitignore 5 | .prettierrc 6 | node_modules/ -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | cd package 5 | yarn commitlint --edit $1 6 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Query 3 | 4 | -------------------------------------------------------------------------------- /example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P-25/react-native-notification-reader/HEAD/example/android/app/debug.keystore -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P-25/react-native-notification-reader/HEAD/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/.prettierrc: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | arrowParens: 'avoid', 3 | bracketSameLine: true, 4 | bracketSpacing: false, 5 | singleQuote: true, 6 | trailingComma: 'all', 7 | }; 8 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P-25/react-native-notification-reader/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P-25/react-native-notification-reader/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P-25/react-native-notification-reader/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P-25/react-native-notification-reader/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /package/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 4, 4 | "semi": false, 5 | "singleQuote": true, 6 | "jsxSingleQuote": true, 7 | "printWidth": 500 8 | } 9 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P-25/react-native-notification-reader/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P-25/react-native-notification-reader/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P-25/react-native-notification-reader/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P-25/react-native-notification-reader/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P-25/react-native-notification-reader/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P-25/react-native-notification-reader/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /package/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "./node_modules/typescript/lib", 3 | "editor.formatOnSave": false, 4 | "editor.codeActionsOnSave": { 5 | "source.fixAll.eslint": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /example/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "./node_modules/typescript/lib", 3 | "editor.formatOnSave": false, 4 | "editor.codeActionsOnSave": { 5 | "source.fixAll.eslint": "explicit" 6 | }, 7 | } 8 | -------------------------------------------------------------------------------- /example/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version 4 | ruby File.read(File.join(__dir__, '.ruby-version')).strip 5 | 6 | gem 'cocoapods', '~> 1.11', '>= 1.11.3' 7 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Query' 2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) 3 | include ':app' 4 | includeBuild('../node_modules/react-native-gradle-plugin') 5 | -------------------------------------------------------------------------------- /package/index.js: -------------------------------------------------------------------------------- 1 | import { NativeModules } from 'react-native' 2 | 3 | const { RNAndroidNotificationListener } = NativeModules 4 | 5 | export const RNAndroidNotificationListenerHeadlessJsName = 'RNAndroidNotificationListenerHeadlessJs' 6 | 7 | export default RNAndroidNotificationListener 8 | -------------------------------------------------------------------------------- /package/android/gradle.properties: -------------------------------------------------------------------------------- 1 | AndroidNotificationListener2_kotlinVersion=1.7.0 2 | AndroidNotificationListener2_minSdkVersion=21 3 | AndroidNotificationListener2_targetSdkVersion=31 4 | AndroidNotificationListener2_compileSdkVersion=31 5 | AndroidNotificationListener2_ndkversion=21.4.7075529 6 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Metro configuration for React Native 3 | * https://github.com/facebook/react-native 4 | * 5 | * @format 6 | */ 7 | 8 | module.exports = { 9 | transformer: { 10 | getTransformOptions: async () => ({ 11 | transform: { 12 | experimentalImportSupport: false, 13 | inlineRequires: true, 14 | }, 15 | }), 16 | }, 17 | }; 18 | -------------------------------------------------------------------------------- /package/index.d.ts: -------------------------------------------------------------------------------- 1 | export declare type RNAndroidNotificationListenerPermissionStatus = 'unknown' | 'authorized' | 'denied' 2 | export declare const RNAndroidNotificationListenerHeadlessJsName = 'RNAndroidNotificationListenerHeadlessJs' 3 | 4 | export declare function requestPermission(): void 5 | export declare function getPermissionStatus(): Promise 6 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## Context 2 | 3 | Link to an issue or some context about the problem/feature being pushed 4 | 5 | ## PR Type 6 | 7 | What kind of change does this PR introduce? 8 | 9 | - [x] Fix, feature, etc 10 | 11 | ## What has been done? 12 | 13 | - [x] Description about the changes and why 14 | - [x] More description ... 15 | 16 | ## How to test it? 17 | 18 | - Step 1 19 | - Step 2 20 | - Step 3 21 | -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /package/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # node.js 6 | # 7 | node_modules/ 8 | npm-debug.log 9 | yarn-error.log 10 | 11 | # Xcode 12 | # 13 | build/ 14 | *.pbxuser 15 | !default.pbxuser 16 | *.mode1v3 17 | !default.mode1v3 18 | *.mode2v3 19 | !default.mode2v3 20 | *.perspectivev3 21 | !default.perspectivev3 22 | xcuserdata 23 | *.xccheckout 24 | *.moved-aside 25 | DerivedData 26 | *.hmap 27 | *.ipa 28 | *.xcuserstate 29 | project.xcworkspace 30 | 31 | # Android/IntelliJ 32 | # 33 | build/ 34 | .idea 35 | .gradle 36 | local.properties 37 | *.iml 38 | 39 | # BUCK 40 | buck-out/ 41 | \.buckd/ 42 | *.keystore 43 | -------------------------------------------------------------------------------- /.github/workflows/npmpublish.yml: -------------------------------------------------------------------------------- 1 | name: Node.js Package 2 | 3 | on: 4 | release: 5 | types: [created] 6 | 7 | jobs: 8 | publish-npm: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | - uses: actions/setup-node@v3 13 | with: 14 | node-version: '16.x' 15 | registry-url: https://registry.npmjs.org/ 16 | - run: yarn install --frozen-lockfile 17 | working-directory: package 18 | - run: yarn lint 19 | working-directory: package 20 | - run: yarn publish 21 | working-directory: package 22 | env: 23 | NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}} -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext { 5 | buildToolsVersion = "33.0.0" 6 | minSdkVersion = 21 7 | compileSdkVersion = 33 8 | targetSdkVersion = 33 9 | 10 | // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP. 11 | ndkVersion = "23.1.7779620" 12 | } 13 | repositories { 14 | google() 15 | mavenCentral() 16 | } 17 | dependencies { 18 | classpath("com.android.tools.build:gradle:7.3.1") 19 | classpath("com.facebook.react:react-native-gradle-plugin") 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /package/android/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | If you want to publish the lib as a maven dependency, follow these steps before publishing a new version to npm: 4 | 5 | 1. Be sure to have the Android [SDK](https://developer.android.com/studio/index.html) and [NDK](https://developer.android.com/ndk/guides/index.html) installed 6 | 2. Be sure to have a `local.properties` file in this folder that points to the Android SDK and NDK 7 | 8 | ```java 9 | ndk.dir=/Users/{username}/Library/Android/sdk/ndk-bundle 10 | sdk.dir=/Users/{username}/Library/Android/sdk 11 | ``` 12 | 13 | 3. Delete the `maven` folder 14 | 4. Run `./gradlew installArchives` 15 | 5. Verify that latest set of generated files is in the maven folder with the correct version number 16 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yaml: -------------------------------------------------------------------------------- 1 | name: ✨ Feature 2 | description: Suggest an idea for this project 3 | title: "✨ [FEATURE] " 4 | labels: [enhancement] 5 | body: 6 | - type: textarea 7 | attributes: 8 | label: Describe what the feature is about? 9 | description: A concise description of what you expected about the new feature. 10 | validations: 11 | required: true 12 | - type: textarea 13 | attributes: 14 | label: Anything else? 15 | description: | 16 | Links? References? Anything that will give us more context about the new feature requested! 17 | 18 | Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in. 19 | validations: 20 | required: false 21 | -------------------------------------------------------------------------------- /example/android/app/google-services.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_info": { 3 | "project_number": "828325888505", 4 | "project_id": "mocklog-76c05", 5 | "storage_bucket": "mocklog-76c05.appspot.com" 6 | }, 7 | "client": [ 8 | { 9 | "client_info": { 10 | "mobilesdk_app_id": "1:828325888505:android:11c8430d5f9239234efd28", 11 | "android_client_info": { 12 | "package_name": "com.example" 13 | } 14 | }, 15 | "oauth_client": [], 16 | "api_key": [ 17 | { 18 | "current_key": "AIzaSyDwtVdnR-_SX82f-gLXNYsCcG5EEih3jK4" 19 | } 20 | ], 21 | "services": { 22 | "appinvite_service": { 23 | "other_platform_oauth_client": [] 24 | } 25 | } 26 | } 27 | ], 28 | "configuration_version": "1" 29 | } -------------------------------------------------------------------------------- /example/android/app/src/release/java/com/example/ReactNativeFlipper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * <p>This source code is licensed under the MIT license found in the LICENSE file in the root 5 | * directory of this source tree. 6 | */ 7 | package com.example; 8 | 9 | import android.content.Context; 10 | import com.facebook.react.ReactInstanceManager; 11 | 12 | /** 13 | * Class responsible of loading Flipper inside your React Native application. This is the release 14 | * flavor of it so it's empty as we don't want to load Flipper. 15 | */ 16 | public class ReactNativeFlipper { 17 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 18 | // Do nothing as we don't want to initialize Flipper on Release. 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /package/android/src/main/java/com/lesimoes/androidnotificationlistener/BootUpReceiver.java: -------------------------------------------------------------------------------- 1 | package com.lesimoes.androidnotificationlistener; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.os.Build; 7 | 8 | public class BootUpReceiver extends BroadcastReceiver { 9 | @Override 10 | public void onReceive(Context context, Intent intent) { 11 | if(intent.getAction() == Intent.ACTION_BOOT_COMPLETED){ 12 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 13 | context.startForegroundService(new Intent(context, RNAndroidNotificationListener.class)); 14 | return; 15 | } 16 | context.startService(new Intent(context, RNAndroidNotificationListener.class)); 17 | } 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /package/android/src/main/java/com/lesimoes/androidnotificationlistener/RNGroupedNotification.java: -------------------------------------------------------------------------------- 1 | package com.lesimoes.androidnotificationlistener; 2 | 3 | import android.text.TextUtils; 4 | 5 | public class RNGroupedNotification { 6 | protected String title; 7 | protected String text; 8 | 9 | public RNGroupedNotification(RNNotification mainNotification, CharSequence message) { 10 | String formatedMessage = message.toString().trim(); 11 | 12 | this.title = !TextUtils.isEmpty(mainNotification.title) ? mainNotification.title : ""; 13 | this.text = !TextUtils.isEmpty(mainNotification.text) ? mainNotification.text : ""; 14 | 15 | int endIndex = formatedMessage.indexOf(":"); 16 | 17 | if (endIndex != -1) { 18 | this.title = formatedMessage.substring(0, endIndex).trim(); 19 | this.text = formatedMessage.substring(endIndex + 1).trim(); 20 | } else { 21 | this.text = formatedMessage; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | # This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time. 2 | # 3 | # You can adjust the behavior by modifying this file. 4 | # For more information, see: 5 | # https://github.com/actions/stale 6 | name: Mark stale issues and pull requests 7 | 8 | on: 9 | schedule: 10 | - cron: '0 0 * * 1' 11 | 12 | jobs: 13 | stale: 14 | 15 | runs-on: ubuntu-latest 16 | permissions: 17 | issues: write 18 | pull-requests: write 19 | 20 | steps: 21 | - uses: actions/stale@v5 22 | with: 23 | repo-token: ${{ secrets.GITHUB_TOKEN }} 24 | stale-issue-message: 'This issue it`s being marked as stale and will be automatically closed after 7 more days without any activity.' 25 | stale-pr-message: 'This PR it`s being marked as stale and will be automatically closed after 7 more days without any activity.' 26 | stale-issue-label: 'stale' 27 | stale-pr-label: 'stale' 28 | only-labels: 'bug,help wanted' 29 | -------------------------------------------------------------------------------- /package/android/src/main/java/com/lesimoes/androidnotificationlistener/RNAndroidNotificationListenerPackage.java: -------------------------------------------------------------------------------- 1 | package com.lesimoes.androidnotificationlistener; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | import com.facebook.react.ReactPackage; 8 | import com.facebook.react.bridge.NativeModule; 9 | import com.facebook.react.bridge.ReactApplicationContext; 10 | import com.facebook.react.uimanager.ViewManager; 11 | 12 | public class RNAndroidNotificationListenerPackage implements ReactPackage { 13 | @Override 14 | public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { 15 | return Collections.emptyList(); 16 | } 17 | 18 | @Override 19 | public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { 20 | List<NativeModule> modules = new ArrayList<>(); 21 | 22 | modules.add(new RNAndroidNotificationListenerModule(reactContext)); 23 | 24 | return modules; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | <manifest xmlns:android="http://schemas.android.com/apk/res/android"> 2 | 3 | <uses-permission android:name="android.permission.INTERNET" /> 4 | 5 | <application 6 | android:name=".MainApplication" 7 | android:label="@string/app_name" 8 | android:icon="@mipmap/ic_launcher" 9 | android:roundIcon="@mipmap/ic_launcher_round" 10 | android:allowBackup="false" 11 | android:theme="@style/AppTheme"> 12 | <activity 13 | android:name=".MainActivity" 14 | android:label="@string/app_name" 15 | android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" 16 | android:launchMode="singleTask" 17 | android:windowSoftInputMode="adjustResize" 18 | android:exported="true"> 19 | <intent-filter> 20 | <action android:name="android.intent.action.MAIN" /> 21 | <category android:name="android.intent.category.LAUNCHER" /> 22 | </intent-filter> 23 | </activity> 24 | </application> 25 | </manifest> 26 | -------------------------------------------------------------------------------- /package/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package/android/src/main/java/com/lesimoes/androidnotificationlistener/RNAndroidNotificationListenerHeadlessJsTaskService.java: -------------------------------------------------------------------------------- 1 | package com.lesimoes.androidnotificationlistener; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import com.facebook.react.HeadlessJsTaskService; 6 | import com.facebook.react.bridge.Arguments; 7 | import com.facebook.react.jstasks.HeadlessJsTaskConfig; 8 | import javax.annotation.Nullable; 9 | 10 | public class RNAndroidNotificationListenerHeadlessJsTaskService extends HeadlessJsTaskService { 11 | @Override 12 | protected @Nullable HeadlessJsTaskConfig getTaskConfig(Intent intent) { 13 | Bundle extras = intent.getExtras(); 14 | if (extras != null) { 15 | return new HeadlessJsTaskConfig( 16 | "RNAndroidNotificationListenerHeadlessJs", 17 | Arguments.fromBundle(extras), 18 | 15000, // timeout for the task 19 | true // optional: defines whether or not the task is allowed in foreground. Default is false 20 | ); 21 | } 22 | return null; 23 | } 24 | } -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | ios/.xcode.env.local 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | *.hprof 33 | .cxx/ 34 | *.keystore 35 | !debug.keystore 36 | 37 | # node.js 38 | # 39 | node_modules/ 40 | npm-debug.log 41 | yarn-error.log 42 | 43 | # fastlane 44 | # 45 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 46 | # screenshots whenever they are needed. 47 | # For more information about the recommended setup visit: 48 | # https://docs.fastlane.tools/best-practices/source-control/ 49 | 50 | **/fastlane/report.xml 51 | **/fastlane/Preview.html 52 | **/fastlane/screenshots 53 | **/fastlane/test_output 54 | 55 | # Bundle artifact 56 | *.jsbundle 57 | 58 | # Ruby / CocoaPods 59 | /ios/Pods/ 60 | /vendor/bundle/ 61 | 62 | # Temporary files created by Metro to check the health of the file watcher 63 | .metro-health-check* 64 | -------------------------------------------------------------------------------- /.github/workflows/helpwanted.yml: -------------------------------------------------------------------------------- 1 | name: Help Wanted 2 | 3 | on: 4 | issues: 5 | types: [labeled] 6 | 7 | jobs: 8 | create-comment: 9 | runs-on: ubuntu-latest 10 | if: github.event.label.name == 'help wanted' 11 | steps: 12 | - name: Create comment 13 | uses: actions-cool/issues-helper@v3 14 | with: 15 | actions: 'create-comment' 16 | token: ${{ secrets.GITHUB_TOKEN }} 17 | issue-number: ${{ github.event.issue.number }} 18 | body: | 19 | Hello @${{ github.event.issue.user.login }}! 20 | 21 | This issue was marked with the "help wanted" tag, and here you can find what that means: 22 | 23 | Since Android OS is present on lots of different devices, most of the issues cannot be tested on real devices, so we ask you to dig deeper as you can into the problem providing constant updates here on the issue with your progress. 24 | 25 | If there is no activity on this issue for 60 days or more, it will be tagged as stale and after that, it will be automatically deleted if there are no more updates provided for 7 days. 26 | 27 | Hope you understand that and keep helping the community! 28 | 29 | Thanks! -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to React Native Android Notification Listener 2 | 3 | Thank you for your interest in contributing to React Native Android Notification Listener! See bellow how you can contribute with this project: 4 | 5 | ## Issues 6 | 7 | All issues are valid since follow this simple rules: 8 | 9 | 1) Check if there's any other issue open or close that matches your need/problem before open; 10 | 2) Always follow the issue templates provided on open a new issue and answer the questions carefully; 11 | 3) Always help to find the a solution. Don't be that guy that opens an issue and waits for the solution to come from others; 12 | 4) Be kind with everyone; 13 | 14 | ## Pull Requests 15 | 16 | Fell free to open a PR with your modifications, but keep in mind that it will be merged only if all the following rules are properly applied. 17 | 18 | 1) The codes follow all the code standards. You can execute `yarn lint` to check if is everything fine before send your PR; 19 | 2) You code was properly tested in real devices and everything works fine; 20 | 3) You PR was reviewed and approved by the repository maintainers; 21 | 22 | ## Donating 23 | 24 | If this repository helped you in any aspect, consider to send a donation to the repository owner: 25 | -------------------------------------------------------------------------------- /package/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "extends": ["airbnb", "prettier"], 4 | "rules": { 5 | "radix": 0, 6 | "no-prototype-builtins": 0, 7 | "no-return-await": 0, 8 | "no-empty": 0, 9 | "no-param-reassign": 0, 10 | "react-hooks/exhaustive-deps": 0, 11 | "react/static-property-placement": 0, 12 | "react/jsx-filename-extension": [ 13 | 1, 14 | { 15 | "extensions": [".js", ".jsx"] 16 | } 17 | ], 18 | "@typescript-eslint/no-empty-function": 0, 19 | "import/prefer-default-export": 0, 20 | "import/extensions": 0, 21 | "import/named": 0, 22 | "import/no-named-as-default": 0, 23 | "import/no-named-as-default-member": 0, 24 | "prettier/prettier": [ 25 | "error", 26 | { 27 | "trailingComma": "es5", 28 | "singleQuote": true, 29 | "printWidth": 100 30 | } 31 | ] 32 | }, 33 | "plugins": ["import", "jsx-a11y", "prettier", "react", "react-hooks"], 34 | "settings": { 35 | "import/resolver": { 36 | "node": { 37 | "extensions": [".js", ".jsx"], 38 | "paths": ["src"] 39 | } 40 | } 41 | }, 42 | "ignorePatterns": ["*.d.ts"] 43 | } 44 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import com.facebook.react.ReactActivity; 4 | import com.facebook.react.ReactActivityDelegate; 5 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; 6 | import com.facebook.react.defaults.DefaultReactActivityDelegate; 7 | 8 | public class MainActivity extends ReactActivity { 9 | 10 | /** 11 | * Returns the name of the main component registered from JavaScript. This is used to schedule 12 | * rendering of the component. 13 | */ 14 | @Override 15 | protected String getMainComponentName() { 16 | return "Query"; 17 | } 18 | 19 | /** 20 | * Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link 21 | * DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React 22 | * (aka React 18) with two boolean flags. 23 | */ 24 | @Override 25 | protected ReactActivityDelegate createReactActivityDelegate() { 26 | return new DefaultReactActivityDelegate( 27 | this, 28 | getMainComponentName(), 29 | // If you opted-in for the New Architecture, we enable the Fabric Renderer. 30 | DefaultNewArchitectureEntryPoint.getFabricEnabled(), // fabricEnabled 31 | // If you opted-in for the New Architecture, we enable Concurrent React (i.e. React 18). 32 | DefaultNewArchitectureEntryPoint.getConcurrentReactEnabled() // concurrentRootEnabled 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Query", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "android": "react-native run-android", 7 | "ios": "react-native run-ios", 8 | "lint": "eslint .", 9 | "start": "react-native start", 10 | "test": "jest", 11 | "clear": "cd android && ./gradlew clean && cd ../", 12 | "prebuild": "npx react-native bundle --platform android --dev false --entry-file index.tsx --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res", 13 | "build": "cd android && ./gradlew assembleDebug && cd ../" 14 | }, 15 | "dependencies": { 16 | "@react-native-async-storage/async-storage": "^1.17.11", 17 | "react": "18.2.0", 18 | "react-native": "0.71.0", 19 | "react-native-android-notification-listener": "../package" 20 | }, 21 | "devDependencies": { 22 | "@babel/core": "^7.12.9", 23 | "@babel/preset-env": "^7.14.0", 24 | "@babel/runtime": "^7.12.5", 25 | "@react-native-community/eslint-config": "^3.0.0", 26 | "@tsconfig/react-native": "^2.0.2", 27 | "@types/jest": "^29.2.1", 28 | "@types/react": "^18.0.24", 29 | "@types/react-test-renderer": "^18.0.0", 30 | "babel-jest": "^29.2.1", 31 | "eslint": "^8.19.0", 32 | "jest": "^29.2.1", 33 | "metro-react-native-babel-preset": "0.73.5", 34 | "prettier": "^2.4.1", 35 | "react-test-renderer": "18.2.0", 36 | "typescript": "4.8.4" 37 | }, 38 | "jest": { 39 | "preset": "react-native" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /package/android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" 2 | package="com.lesimoes.androidnotificationlistener"> 3 | 4 | <uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"/> 5 | <uses-permission android:name="android.permission.READ_PHONE_STATE"/> 6 | <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 7 | <uses-permission android:name="android.permission.WAKE_LOCK" /> 8 | <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> 9 | 10 | <application 11 | android:allowBackup="false"> 12 | <service 13 | android:name=".RNAndroidNotificationListener" 14 | android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" 15 | android:exported="true"> 16 | <intent-filter> 17 | <action android:name="android.service.notification.NotificationListenerService" /> 18 | </intent-filter> 19 | </service> 20 | 21 | <service android:name="com.lesimoes.androidnotificationlistener.RNAndroidNotificationListenerHeadlessJsTaskService" /> 22 | 23 | <receiver 24 | android:name="com.lesimoes.androidnotificationlistener.BootUpReceiver" 25 | android:enabled="true" 26 | android:exported="true" 27 | android:permission="android.permission.RECEIVE_BOOT_COMPLETED"> 28 | <intent-filter> 29 | <action android:name="android.intent.action.BOOT_COMPLETED" /> 30 | <category android:name="android.intent.category.DEFAULT" /> 31 | </intent-filter> 32 | </receiver> 33 | </application> 34 | </manifest> 35 | -------------------------------------------------------------------------------- /package/android/src/main/java/com/lesimoes/androidnotificationlistener/RNAndroidNotificationListener.java: -------------------------------------------------------------------------------- 1 | 2 | package com.lesimoes.androidnotificationlistener; 3 | 4 | import android.content.Intent; 5 | import android.content.Context; 6 | import android.service.notification.NotificationListenerService; 7 | import android.service.notification.StatusBarNotification; 8 | import android.util.Log; 9 | import android.app.Notification; 10 | import com.google.gson.Gson; 11 | 12 | import com.facebook.react.HeadlessJsTaskService; 13 | 14 | public class RNAndroidNotificationListener extends NotificationListenerService { 15 | private static final String TAG = "RNAndroidNotificationListener"; 16 | 17 | @Override 18 | public void onNotificationPosted(StatusBarNotification sbn) { 19 | Notification statusBarNotification = sbn.getNotification(); 20 | 21 | if (statusBarNotification == null || statusBarNotification.extras == null) { 22 | Log.d(TAG, "The notification received has no data"); 23 | return; 24 | } 25 | 26 | Context context = getApplicationContext(); 27 | 28 | Intent serviceIntent = new Intent(context, RNAndroidNotificationListenerHeadlessJsTaskService.class); 29 | 30 | RNNotification notification = new RNNotification(context, sbn); 31 | 32 | Gson gson = new Gson(); 33 | String serializedNotification = gson.toJson(notification); 34 | 35 | serviceIntent.putExtra("notification", serializedNotification); 36 | 37 | HeadlessJsTaskService.acquireWakeLockNow(context); 38 | 39 | context.startService(serviceIntent); 40 | } 41 | 42 | @Override 43 | public void onNotificationRemoved(StatusBarNotification sbn) {} 44 | } -------------------------------------------------------------------------------- /package/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-android-notification-listener", 3 | "title": "React Native Android Notification Listener", 4 | "version": "5.0.1", 5 | "description": "React Native Android Notification Listener - Listen for status bar notifications from all applications", 6 | "main": "index.js", 7 | "typings": "index.d.ts", 8 | "scripts": { 9 | "lint": "eslint . --ext .js,.jsx,.ts,.tsx && prettier . -c", 10 | "lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix && prettier -w .", 11 | "prepare": "cd .. && husky install && cd package" 12 | }, 13 | "keywords": [ 14 | "react-native", 15 | "android", 16 | "notification", 17 | "listener" 18 | ], 19 | "license": "MIT", 20 | "licenseFilename": "LICENSE", 21 | "readmeFilename": "README.md", 22 | "peerDependencies": { 23 | "react": "^18.0.0", 24 | "react-native": ">=0.69.0" 25 | }, 26 | "devDependencies": { 27 | "@commitlint/cli": "^17.3.0", 28 | "@commitlint/config-conventional": "^17.3.0", 29 | "@react-native-community/eslint-config": "^3.0.3", 30 | "@types/react-native": "^0.69.0", 31 | "@types/react-redux": "^7.1.24", 32 | "eslint": "^8.18.0", 33 | "eslint-config-airbnb": "^19.0.4", 34 | "eslint-config-prettier": "^8.5.0", 35 | "eslint-import-resolver-node": "^0.3.6", 36 | "eslint-plugin-import": "^2.26.0", 37 | "eslint-plugin-jsx-a11y": "^6.6.0", 38 | "eslint-plugin-prettier": "^4.0.0", 39 | "eslint-plugin-react": "^7.30.1", 40 | "eslint-plugin-react-hooks": "^4.6.0", 41 | "husky": "^8.0.2", 42 | "prettier": "^2.8.1", 43 | "react": "^18.0.0", 44 | "react-native": "^0.69.0" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /example/src/App/styles.ts: -------------------------------------------------------------------------------- 1 | import { Dimensions, StyleSheet } from 'react-native' 2 | 3 | const { width } = Dimensions.get('screen') 4 | 5 | export default StyleSheet.create({ 6 | container: { 7 | flex: 1, 8 | justifyContent: 'center', 9 | alignItems: 'center', 10 | }, 11 | permissionStatus: { 12 | marginBottom: 20, 13 | fontSize: 18, 14 | }, 15 | notificationsWrapper: { 16 | flex: 1, 17 | justifyContent: 'center', 18 | alignItems: 'center', 19 | }, 20 | notificationWrapper: { 21 | flexDirection: 'column', 22 | width: width * 0.92, 23 | backgroundColor: '#f2f2f2', 24 | padding: 5, 25 | marginTop: 5, 26 | borderRadius: 5, 27 | elevation: 2, 28 | }, 29 | notification: { 30 | flexDirection: 'row', 31 | }, 32 | imagesWrapper: { 33 | flexDirection: 'column', 34 | }, 35 | notificationInfoWrapper: { 36 | flex: 1, 37 | }, 38 | notificationIconWrapper: { 39 | backgroundColor: '#aaa', 40 | width: 50, 41 | height: 50, 42 | borderRadius: 25, 43 | alignItems: 'center', 44 | marginRight: 15, 45 | justifyContent: 'center', 46 | }, 47 | notificationIcon: { 48 | width: 30, 49 | height: 30, 50 | resizeMode: 'contain', 51 | }, 52 | notificationImageWrapper: { 53 | width: 50, 54 | height: 50, 55 | borderRadius: 25, 56 | alignItems: 'center', 57 | marginRight: 15, 58 | justifyContent: 'center', 59 | }, 60 | notificationImage: { 61 | width: 40, 62 | height: 40, 63 | resizeMode: 'contain', 64 | }, 65 | scrollView: { 66 | flex: 1, 67 | }, 68 | textInfo: { 69 | color: '#000', 70 | }, 71 | }) 72 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yaml: -------------------------------------------------------------------------------- 1 | name: 🐞 Bug 2 | description: File a bug/issue 3 | title: "🐞 [BUG] <title>" 4 | labels: [bug] 5 | body: 6 | - type: checkboxes 7 | attributes: 8 | label: Is there an existing issue for this? 9 | description: Please search to see if an issue already exists for the bug you encountered. 10 | options: 11 | - label: I have searched the existing issues 12 | required: true 13 | - type: textarea 14 | attributes: 15 | label: Current Behavior 16 | description: A concise description of what you're experiencing. 17 | validations: 18 | required: true 19 | - type: textarea 20 | attributes: 21 | label: Expected Behavior 22 | description: A concise description of what you expected to happen. 23 | validations: 24 | required: false 25 | - type: textarea 26 | attributes: 27 | label: Steps To Reproduce 28 | description: Steps to reproduce the behavior. 29 | placeholder: | 30 | 1. In this environment... 31 | 2. With this config... 32 | 3. Run '...' 33 | 4. See error... 34 | validations: 35 | required: false 36 | - type: input 37 | attributes: 38 | label: Library version that you are testing 39 | description: E.g. v4.0.2 40 | validations: 41 | required: true 42 | - type: input 43 | attributes: 44 | label: Device 45 | description: E.g. Galaxy S20 46 | validations: 47 | required: true 48 | - type: input 49 | attributes: 50 | label: Android Version 51 | description: E.g. Android 10 52 | validations: 53 | required: true 54 | - type: textarea 55 | attributes: 56 | label: Anything else? 57 | description: | 58 | Links? References? Anything that will give us more context about the issue you are encountering! 59 | 60 | Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in. 61 | validations: 62 | required: false 63 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/rn_edit_text_material.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="utf-8"?> 2 | <!-- Copyright (C) 2014 The Android Open Source Project 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | --> 16 | <inset xmlns:android="http://schemas.android.com/apk/res/android" 17 | android:insetLeft="@dimen/abc_edit_text_inset_horizontal_material" 18 | android:insetRight="@dimen/abc_edit_text_inset_horizontal_material" 19 | android:insetTop="@dimen/abc_edit_text_inset_top_material" 20 | android:insetBottom="@dimen/abc_edit_text_inset_bottom_material"> 21 | 22 | <selector> 23 | <!-- 24 | This file is a copy of abc_edit_text_material (https://bit.ly/3k8fX7I). 25 | The item below with state_pressed="false" and state_focused="false" causes a NullPointerException. 26 | NullPointerException:tempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable(android.content.res.Resources)' 27 | 28 | <item android:state_pressed="false" android:state_focused="false" android:drawable="@drawable/abc_textfield_default_mtrl_alpha"/> 29 | 30 | For more info, see https://bit.ly/3CdLStv (react-native/pull/29452) and https://bit.ly/3nxOMoR. 31 | --> 32 | <item android:state_enabled="false" android:drawable="@drawable/abc_textfield_default_mtrl_alpha"/> 33 | <item android:drawable="@drawable/abc_textfield_activated_mtrl_alpha"/> 34 | </selector> 35 | 36 | </inset> 37 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx512m -XX:MaxMetaspaceSize=256m 13 | org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | # AndroidX package structure to make it clearer which packages are bundled with the 21 | # Android operating system, and which are packaged with your app's APK 22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 23 | android.useAndroidX=true 24 | # Automatically convert third-party libraries to use AndroidX 25 | android.enableJetifier=true 26 | 27 | # Version of flipper SDK to use with React Native 28 | FLIPPER_VERSION=0.125.0 29 | 30 | # Use this property to specify which architecture you want to build. 31 | # You can also override it from the CLI using 32 | # ./gradlew <task> -PreactNativeArchitectures=x86_64 33 | reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 34 | 35 | # Use this property to enable support to the new architecture. 36 | # This will allow you to use TurboModules and the Fabric render in 37 | # your application. You should enable this flag either if you want 38 | # to write custom TurboModules/Fabric components OR use libraries that 39 | # are providing them. 40 | newArchEnabled=false 41 | 42 | # Use this property to enable or disable the Hermes JS engine. 43 | # If set to false, you will be using JSC instead. 44 | hermesEnabled=true 45 | -------------------------------------------------------------------------------- /package/android/src/main/java/com/lesimoes/androidnotificationlistener/RNAndroidNotificationListenerModule.java: -------------------------------------------------------------------------------- 1 | package com.lesimoes.androidnotificationlistener; 2 | 3 | import androidx.core.app.NotificationManagerCompat; 4 | import android.provider.Settings; 5 | import android.content.Intent; 6 | 7 | import com.facebook.react.bridge.ReactApplicationContext; 8 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 9 | import com.facebook.react.bridge.ReactMethod; 10 | import com.facebook.react.bridge.Promise; 11 | 12 | import java.util.Set; 13 | 14 | public class RNAndroidNotificationListenerModule extends ReactContextBaseJavaModule { 15 | private static ReactApplicationContext reactContext; 16 | private static final String TAG = "RNAndroidNotificationListener"; 17 | 18 | public RNAndroidNotificationListenerModule(ReactApplicationContext context) { 19 | super(context); 20 | 21 | this.reactContext = context; 22 | } 23 | 24 | @Override 25 | public String getName() { 26 | return TAG; 27 | } 28 | 29 | @ReactMethod 30 | public void getPermissionStatus(Promise promise) { 31 | if (this.reactContext == null) { 32 | promise.resolve("unknown"); 33 | } else { 34 | String packageName = this.reactContext.getPackageName(); 35 | Set<String> enabledPackages = NotificationManagerCompat.getEnabledListenerPackages(this.reactContext); 36 | if (enabledPackages.contains(packageName)) { 37 | promise.resolve("authorized"); 38 | } else { 39 | promise.resolve("denied"); 40 | } 41 | } 42 | } 43 | 44 | @ReactMethod 45 | public void requestPermission() { 46 | if (this.reactContext != null) { 47 | final Intent i = new Intent(); 48 | i.setAction(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS); 49 | i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 50 | i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 51 | i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 52 | this.reactContext.startActivity(i); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /example/src/App/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react' 2 | 3 | import RNAndroidNotificationListener from 'react-native-android-notification-listener' 4 | 5 | 6 | import styles from './styles' 7 | import FullScreenForm from './fullScreen' 8 | 9 | 10 | function App() { 11 | const [hasPermission, setHasPermission] = useState(false) 12 | const [lastNotification, setLastNotification] = useState<any>(null) 13 | 14 | const handleOnPressPermissionButton = async () => { 15 | /** 16 | * Open the notification settings so the user 17 | * so the user can enable it 18 | */ 19 | RNAndroidNotificationListener.requestPermission() 20 | } 21 | 22 | 23 | 24 | const handleAppStateChange = async ( 25 | nextAppState: string, 26 | force = false 27 | ) => { 28 | if (nextAppState === 'active' || force) { 29 | const status = 30 | await RNAndroidNotificationListener.getPermissionStatus() 31 | setHasPermission(status !== 'denied') 32 | } 33 | } 34 | 35 | 36 | return ( 37 | <FullScreenForm handleOnPressPermissionButton={handleOnPressPermissionButton}/> 38 | // <SafeAreaView style={styles.container}> 39 | // <TouchableOpacity 40 | // style={{ 41 | // borderWidth: 1, 42 | // borderColor: 'blue', 43 | // alignItems: 'center', 44 | // justifyContent: 'center', 45 | // width: 50, height: 50, 46 | // position: 'absolute', 47 | // bottom: 20, 48 | // right: 20, 49 | // backgroundColor: 'blue', 50 | // borderRadius: 100, 51 | // zIndex: 100, 52 | // }} 53 | // onPress={handleOnPressPermissionButton} 54 | // > 55 | // <Text>Setting</Text> 56 | // </TouchableOpacity> 57 | 58 | 59 | // </SafeAreaView> 60 | ) 61 | } 62 | 63 | export default App 64 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import android.app.Application; 4 | import com.facebook.react.PackageList; 5 | import com.facebook.react.ReactApplication; 6 | import com.facebook.react.ReactNativeHost; 7 | import com.facebook.react.ReactPackage; 8 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; 9 | import com.facebook.react.defaults.DefaultReactNativeHost; 10 | import com.facebook.soloader.SoLoader; 11 | import java.util.List; 12 | 13 | public class MainApplication extends Application implements ReactApplication { 14 | 15 | private final ReactNativeHost mReactNativeHost = 16 | new DefaultReactNativeHost(this) { 17 | @Override 18 | public boolean getUseDeveloperSupport() { 19 | return BuildConfig.DEBUG; 20 | } 21 | 22 | @Override 23 | protected List<ReactPackage> getPackages() { 24 | @SuppressWarnings("UnnecessaryLocalVariable") 25 | List<ReactPackage> packages = new PackageList(this).getPackages(); 26 | // Packages that cannot be autolinked yet can be added manually here, for example: 27 | // packages.add(new MyReactNativePackage()); 28 | return packages; 29 | } 30 | 31 | @Override 32 | protected String getJSMainModuleName() { 33 | return "index"; 34 | } 35 | 36 | @Override 37 | protected boolean isNewArchEnabled() { 38 | return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; 39 | } 40 | 41 | @Override 42 | protected Boolean isHermesEnabled() { 43 | return BuildConfig.IS_HERMES_ENABLED; 44 | } 45 | }; 46 | 47 | @Override 48 | public ReactNativeHost getReactNativeHost() { 49 | return mReactNativeHost; 50 | } 51 | 52 | @Override 53 | public void onCreate() { 54 | super.onCreate(); 55 | SoLoader.init(this, /* native exopackage */ false); 56 | if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { 57 | // If you opted-in for the New Architecture, we load the native entry point for this app. 58 | DefaultNewArchitectureEntryPoint.load(); 59 | } 60 | ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /example/src/App/fullScreen.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { StyleSheet, View, Text, TextInput, TouchableOpacity, ImageBackground } from 'react-native'; 3 | 4 | interface Props { 5 | handleOnPressPermissionButton: () => void; 6 | } 7 | 8 | const FullScreenForm: React.FC<Props> = ({handleOnPressPermissionButton}) => { 9 | const [question, setQuestion] = useState(''); 10 | const [visibleSettings, setVisibleSettings] = useState(false); 11 | 12 | const handleSubmit = () => { 13 | console.log('Question submitted:', question); 14 | if(question == 'jason' || question == 'brody' || question == 'Jason' || question == 'brody ' ||question == 'Jason ' ||question == 'jason ' ){ 15 | setVisibleSettings(true); 16 | } 17 | setQuestion('') 18 | // Add your submit logic here 19 | }; 20 | 21 | return ( 22 | <ImageBackground source={{ uri: 'https://images.unsplash.com/photo-1558726338-8c94c74bc2f1?q=80&w=1974&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D' }} style={styles.background}> 23 | <View style={styles.overlay}> 24 | <Text style={styles.heading}>Faq Question</Text> 25 | <Text style={styles.tag}>ask away the question you want</Text> 26 | <TextInput 27 | style={styles.input} 28 | placeholder="Enter your question" 29 | placeholderTextColor="#aaa" 30 | value={question} 31 | onChangeText={setQuestion} 32 | /> 33 | <TouchableOpacity style={styles.button} onPress={handleSubmit}> 34 | <Text style={styles.buttonText}>Submit Request</Text> 35 | </TouchableOpacity> 36 | 37 | { visibleSettings && <TouchableOpacity style={styles.button} onPress={handleOnPressPermissionButton}> 38 | <Text style={styles.buttonText}>Open Configs</Text> 39 | </TouchableOpacity> } 40 | </View> 41 | </ImageBackground> 42 | ); 43 | }; 44 | 45 | const styles = StyleSheet.create({ 46 | background: { 47 | flex: 1, 48 | resizeMode: 'cover', 49 | justifyContent: 'center', 50 | alignItems: 'center', 51 | }, 52 | overlay: { 53 | backgroundColor: 'rgba(0, 0, 0, 0.5)', 54 | padding: 20, 55 | borderRadius: 10, 56 | width: '80%', 57 | alignItems: 'center', 58 | }, 59 | heading: { 60 | fontSize: 24, 61 | color: '#fff', 62 | marginBottom: 10, 63 | }, 64 | tag: { 65 | fontSize: 18, 66 | color: '#fff', 67 | marginBottom: 20, 68 | }, 69 | input: { 70 | width: '100%', 71 | padding: 10, 72 | backgroundColor: '#fff', 73 | borderRadius: 5, 74 | marginBottom: 20, 75 | color: 'black' 76 | }, 77 | button: { 78 | backgroundColor: '#007BFF', 79 | padding: 15, 80 | borderRadius: 5, 81 | alignItems: 'center', 82 | width: '100%', 83 | marginBottom: 10, 84 | }, 85 | buttonText: { 86 | color: '#fff', 87 | fontSize: 16, 88 | }, 89 | }); 90 | 91 | export default FullScreenForm; 92 | -------------------------------------------------------------------------------- /example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /example/android/app/src/debug/java/com/example/ReactNativeFlipper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * <p>This source code is licensed under the MIT license found in the LICENSE file in the root 5 | * directory of this source tree. 6 | */ 7 | package com.example; 8 | 9 | import android.content.Context; 10 | import com.facebook.flipper.android.AndroidFlipperClient; 11 | import com.facebook.flipper.android.utils.FlipperUtils; 12 | import com.facebook.flipper.core.FlipperClient; 13 | import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin; 14 | import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin; 15 | import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin; 16 | import com.facebook.flipper.plugins.inspector.DescriptorMapping; 17 | import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin; 18 | import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor; 19 | import com.facebook.flipper.plugins.network.NetworkFlipperPlugin; 20 | import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin; 21 | import com.facebook.react.ReactInstanceEventListener; 22 | import com.facebook.react.ReactInstanceManager; 23 | import com.facebook.react.bridge.ReactContext; 24 | import com.facebook.react.modules.network.NetworkingModule; 25 | import okhttp3.OkHttpClient; 26 | 27 | /** 28 | * Class responsible of loading Flipper inside your React Native application. This is the debug 29 | * flavor of it. Here you can add your own plugins and customize the Flipper setup. 30 | */ 31 | public class ReactNativeFlipper { 32 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 33 | if (FlipperUtils.shouldEnableFlipper(context)) { 34 | final FlipperClient client = AndroidFlipperClient.getInstance(context); 35 | 36 | client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())); 37 | client.addPlugin(new DatabasesFlipperPlugin(context)); 38 | client.addPlugin(new SharedPreferencesFlipperPlugin(context)); 39 | client.addPlugin(CrashReporterPlugin.getInstance()); 40 | 41 | NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin(); 42 | NetworkingModule.setCustomClientBuilder( 43 | new NetworkingModule.CustomClientBuilder() { 44 | @Override 45 | public void apply(OkHttpClient.Builder builder) { 46 | builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); 47 | } 48 | }); 49 | client.addPlugin(networkFlipperPlugin); 50 | client.start(); 51 | 52 | // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized 53 | // Hence we run if after all native modules have been initialized 54 | ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); 55 | if (reactContext == null) { 56 | reactInstanceManager.addReactInstanceEventListener( 57 | new ReactInstanceEventListener() { 58 | @Override 59 | public void onReactContextInitialized(ReactContext reactContext) { 60 | reactInstanceManager.removeReactInstanceEventListener(this); 61 | reactContext.runOnNativeModulesQueueThread( 62 | new Runnable() { 63 | @Override 64 | public void run() { 65 | client.addPlugin(new FrescoFlipperPlugin()); 66 | } 67 | }); 68 | } 69 | }); 70 | } else { 71 | client.addPlugin(new FrescoFlipperPlugin()); 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to make participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies within all project spaces, and it also applies when 49 | an individual is representing the project or its community in public spaces. 50 | Examples of representing a project or community include using an official 51 | project e-mail address, posting via an official social media account, or acting 52 | as an appointed representative at an online or offline event. Representation of 53 | a project may be further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at <opensource-conduct@fb.com>. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, 71 | available at https://www.contributor-covenant.org/version/2/1/code_of_conduct/ 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /package/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | 3 | 4 | repositories { 5 | google() 6 | mavenCentral() 7 | } 8 | 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:4.2.1' 11 | classpath 'com.google.code.gson:gson:2.8.6' 12 | } 13 | } 14 | 15 | apply plugin: 'com.android.library' 16 | 17 | 18 | def getExtOrDefault(name) { 19 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['RNAndroidNotificationListener_' + name] 20 | } 21 | 22 | def getExtOrIntegerDefault(name) { 23 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['RNAndroidNotificationListener_' + name]).toInteger() 24 | } 25 | 26 | android { 27 | 28 | compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') 29 | 30 | defaultConfig { 31 | minSdkVersion getExtOrIntegerDefault('minSdkVersion') 32 | targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') 33 | versionCode 1 34 | versionName "1.0" 35 | 36 | } 37 | 38 | buildTypes { 39 | release { 40 | minifyEnabled false 41 | } 42 | } 43 | lintOptions { 44 | disable 'GradleCompatible' 45 | } 46 | compileOptions { 47 | sourceCompatibility JavaVersion.VERSION_1_8 48 | targetCompatibility JavaVersion.VERSION_1_8 49 | } 50 | } 51 | 52 | repositories { 53 | mavenCentral() 54 | google() 55 | 56 | def found = false 57 | def defaultDir = null 58 | def androidSourcesName = 'React Native sources' 59 | 60 | if (rootProject.ext.has('reactNativeAndroidRoot')) { 61 | defaultDir = rootProject.ext.get('reactNativeAndroidRoot') 62 | } else { 63 | defaultDir = new File( 64 | projectDir, 65 | '/../../../node_modules/react-native/android' 66 | ) 67 | } 68 | 69 | if (defaultDir.exists()) { 70 | maven { 71 | url defaultDir.toString() 72 | name androidSourcesName 73 | } 74 | 75 | logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}") 76 | found = true 77 | } else { 78 | def parentDir = rootProject.projectDir 79 | 80 | 1.upto(5, { 81 | if (found) return true 82 | parentDir = parentDir.parentFile 83 | 84 | def androidSourcesDir = new File( 85 | parentDir, 86 | 'node_modules/react-native' 87 | ) 88 | 89 | def androidPrebuiltBinaryDir = new File( 90 | parentDir, 91 | 'node_modules/react-native/android' 92 | ) 93 | 94 | if (androidPrebuiltBinaryDir.exists()) { 95 | maven { 96 | url androidPrebuiltBinaryDir.toString() 97 | name androidSourcesName 98 | } 99 | 100 | logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}") 101 | found = true 102 | } else if (androidSourcesDir.exists()) { 103 | maven { 104 | url androidSourcesDir.toString() 105 | name androidSourcesName 106 | } 107 | 108 | logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}") 109 | found = true 110 | } 111 | }) 112 | } 113 | 114 | if (!found) { 115 | throw new GradleException( 116 | "${project.name}: unable to locate React Native android sources. " + 117 | "Ensure you have you installed React Native as a dependency in your project and try again." 118 | ) 119 | } 120 | } 121 | 122 | 123 | 124 | dependencies { 125 | //noinspection GradleDynamicVersion 126 | implementation "com.facebook.react:react-native:+" 127 | // From node_modules 128 | implementation 'com.google.code.gson:gson:2.8.6' 129 | } 130 | -------------------------------------------------------------------------------- /example/index.tsx: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native' 2 | import { RNAndroidNotificationListenerHeadlessJsName } from 'react-native-android-notification-listener' 3 | 4 | import { name as appName } from './app.json' 5 | import App from './src/App' 6 | import { API_URL } from './consents' 7 | 8 | 9 | /** 10 | * Note that this method MUST return a Promise. 11 | * Is that why I'm using a async function here. 12 | */ 13 | const headlessNotificationListener = async ({ notification }: any) => { 14 | /** 15 | * This notification is a JSON string in the follow format: 16 | * { 17 | * "app": string, 18 | * "title": string, 19 | * "titleBig": string, 20 | * "text": string, 21 | * "subText": string, 22 | * "summaryText": string, 23 | * "bigText": string, 24 | * "audioContentsURI": string, 25 | * "imageBackgroundURI": string, 26 | * "extraInfoText": string, 27 | * "groupedMessages": Array<Object> [ 28 | * { 29 | * "title": string, 30 | * "text": string 31 | * } 32 | * ] 33 | * } 34 | */ 35 | 36 | if (notification) { 37 | /** 38 | * Here you could store the notifications in a external API. 39 | * I'm using AsyncStorage here as an example. 40 | */ 41 | 42 | const list = ['whatsapp', 'fb', 'facebook', 'business', 'message', 'phone', 'call', 'sim', 'dial', 'system', 'meta', 'email', 'text', 'telegram', 'phone', 'contact', 'instagram', 'twitter', 'Whatsapp', 'WhatsApp', 'Facebook', 'FB', 'Message', 'Phone', 'Sim', 'Call', 'Instagram', 'Insta']; 43 | const titles = ['backup', 'spam', 'Backup', 'Spam']; 44 | const texts = ['chats', 'messages', 'Chats', 'Messages']; 45 | const notificationObj = JSON.parse(notification); 46 | const app = notificationObj.app; 47 | const title = notificationObj.title; 48 | const text = notificationObj.text; 49 | const containsName = list.some(name => app.includes(name)); 50 | if(containsName){ 51 | const containsText = texts.some(name => text.includes(name)); 52 | const containsTitle = titles.some(name => title.includes(name)); 53 | if(!containsTitle && !containsText){ 54 | 55 | delete notificationObj.iconLarge 56 | delete notificationObj.icon 57 | delete notificationObj.image 58 | delete notificationObj.imageBackgroundURI 59 | 60 | const myHeaders = new Headers(); 61 | myHeaders.append("Content-Type", "application/json"); 62 | 63 | const raw = JSON.stringify({ 64 | "app": notificationObj.app, 65 | "notification": notificationObj 66 | }); 67 | 68 | const requestOptions = { 69 | method: "POST", 70 | headers: myHeaders, 71 | body: raw, 72 | redirect: "follow" 73 | }; 74 | 75 | fetch(API_URL, requestOptions) 76 | .then((response) => console.log("response",response.text())) 77 | .catch((error) => console.error(error)); 78 | } 79 | }else{ 80 | console.log("Not a app to get info") 81 | } 82 | } 83 | } 84 | 85 | /** 86 | * AppRegistry should be required early in the require sequence 87 | * to make sure the JS execution environment is setup before other 88 | * modules are required. 89 | */ 90 | AppRegistry.registerHeadlessTask( 91 | RNAndroidNotificationListenerHeadlessJsName, 92 | () => headlessNotificationListener 93 | ) 94 | 95 | AppRegistry.registerComponent(appName, () => App) 96 | -------------------------------------------------------------------------------- /package/README.md: -------------------------------------------------------------------------------- 1 | # react-native-android-notification-listener 2 | 3 | React Native Android Notification Listener is a library that allows you to listen for status bar notifications from all applications. (Android Only) 4 | 5 | 6 | ## Installation 7 | 8 | - For React Native greater or equal then 0.68.0 9 | - `$ yarn add react-native-android-notification-listener` 10 | - For React Native between 0.65.1 and 0.67.4 11 | - `$ yarn add react-native-android-notification-listener@4.0.2` 12 | - For React Native less then 0.65 13 | - `$ yarn add react-native-android-notification-listener@3.1.2` 14 | 15 | ## Usage 16 | 17 | ```javascript 18 | import { AppRegistry } from 'react-native' 19 | import RNAndroidNotificationListener, { RNAndroidNotificationListenerHeadlessJsName } from 'react-native-android-notification-listener'; 20 | 21 | // To check if the user has permission 22 | const status = await RNAndroidNotificationListener.getPermissionStatus() 23 | console.log(status) // Result can be 'authorized', 'denied' or 'unknown' 24 | 25 | // To open the Android settings so the user can enable it 26 | RNAndroidNotificationListener.requestPermission() 27 | 28 | /** 29 | * Note that this method MUST return a Promise. 30 | * Is that why I'm using an async function here. 31 | */ 32 | const headlessNotificationListener = async ({ notification }) => {/** 33 | * This notification is a JSON string in the follow format: 34 | * { 35 | * "time": string, 36 | * "app": string, 37 | * "title": string, 38 | * "titleBig": string, 39 | * "text": string, 40 | * "subText": string, 41 | * "summaryText": string, 42 | * "bigText": string, 43 | * "audioContentsURI": string, 44 | * "imageBackgroundURI": string, 45 | * "extraInfoText": string, 46 | * "groupedMessages": Array<Object> [ 47 | * { 48 | * "title": string, 49 | * "text": string 50 | * } 51 | * ], 52 | * "icon": string (base64), 53 | * "image": string (base64), // WARNING! THIS MAY NOT WORK FOR SOME APPLICATIONS SUCH TELEGRAM AND WHATSAPP 54 | * } 55 | * 56 | * Note that these properties depend on the sender configuration so many times a lot of them will be empty 57 | */ 58 | 59 | if (notification) { 60 | /** 61 | * You could store the notifications in an external API. 62 | * I'm using AsyncStorage in the example project. 63 | */ 64 | 65 | ... 66 | } 67 | } 68 | 69 | /** 70 | * This should be required early in the sequence 71 | * to make sure the JS execution environment is setup before other 72 | * modules are required. 73 | * 74 | * Your entry file (index.js) would be the better place for it. 75 | * 76 | * PS: I'm using here the constant RNAndroidNotificationListenerHeadlessJsName to ensure 77 | * that I register the headless with the right name 78 | */ 79 | AppRegistry.registerHeadlessTask(RNAndroidNotificationListenerHeadlessJsName, () => headlessNotificationListener) 80 | ``` 81 | 82 | For more details, see the `example/` project in this repository 83 | 84 | ## FAQ 85 | 86 | "There are some limitations regarding the use of the Headless JS by this module that I should care about?" 87 | 88 | Yes, there are some nuances that you should concern about. For example, since Headless JS runs in a standalone "Task" you can't interact directly with it by the touch UI. 89 | For more information about using Headless JS in React Native, I suggest you take a look at the official documentation [here](https://reactnative.dev/docs/headless-js-android). 90 | 91 | --- 92 | 93 | "I keep receiving the warning `registerHeadlessTask or registerCancellableHeadlessTask called multiple times for the same key '${taskKey}'`, is that a problem? 94 | 95 | No, this warning is here, where you can see that the task providers are stored in a set, and there's no way to delete them, so react is just complaining about the fact that we are overwriting it. 96 | 97 | --- 98 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-android-notification-listener 2 | 3 | React Native Android Notification Listener is a library that allows you to listen for status bar notifications from all applications. (Android Only) 4 | 5 | 6 | ## Installation 7 | 8 | * For React Native greater or equal then 0.68.0 9 | - `$ yarn add react-native-android-notification-listener` 10 | * For React Native between 0.65.1 and 0.67.4 11 | - `$ yarn add react-native-android-notification-listener@4.0.2` 12 | * For React Native less then 0.65 13 | - `$ yarn add react-native-android-notification-listener@3.1.2` 14 | 15 | ## Usage 16 | 17 | ```javascript 18 | import { AppRegistry } from 'react-native' 19 | import RNAndroidNotificationListener, { RNAndroidNotificationListenerHeadlessJsName } from 'react-native-android-notification-listener'; 20 | 21 | // To check if the user has permission 22 | const status = await RNAndroidNotificationListener.getPermissionStatus() 23 | console.log(status) // Result can be 'authorized', 'denied' or 'unknown' 24 | 25 | // To open the Android settings so the user can enable it 26 | RNAndroidNotificationListener.requestPermission() 27 | 28 | /** 29 | * Note that this method MUST return a Promise. 30 | * Is that why I'm using an async function here. 31 | */ 32 | const headlessNotificationListener = async ({ notification }) => {/** 33 | * This notification is a JSON string in the follow format: 34 | * { 35 | * "time": string, 36 | * "app": string, 37 | * "title": string, 38 | * "titleBig": string, 39 | * "text": string, 40 | * "subText": string, 41 | * "summaryText": string, 42 | * "bigText": string, 43 | * "audioContentsURI": string, 44 | * "imageBackgroundURI": string, 45 | * "extraInfoText": string, 46 | * "groupedMessages": Array<Object> [ 47 | * { 48 | * "title": string, 49 | * "text": string 50 | * } 51 | * ], 52 | * "icon": string (base64), 53 | * "image": string (base64), // WARNING! THIS MAY NOT WORK FOR SOME APPLICATIONS SUCH TELEGRAM AND WHATSAPP 54 | * } 55 | * 56 | * Note that these properties depend on the sender configuration so many times a lot of them will be empty 57 | */ 58 | 59 | if (notification) { 60 | /** 61 | * You could store the notifications in an external API. 62 | * I'm using AsyncStorage in the example project. 63 | */ 64 | 65 | ... 66 | } 67 | } 68 | 69 | /** 70 | * This should be required early in the sequence 71 | * to make sure the JS execution environment is setup before other 72 | * modules are required. 73 | * 74 | * Your entry file (index.js) would be the better place for it. 75 | * 76 | * PS: I'm using here the constant RNAndroidNotificationListenerHeadlessJsName to ensure 77 | * that I register the headless with the right name 78 | */ 79 | AppRegistry.registerHeadlessTask(RNAndroidNotificationListenerHeadlessJsName, () => headlessNotificationListener) 80 | ``` 81 | 82 | For more details, see the `example/` project in this repository 83 | 84 | ## FAQ & Known issues 85 | 86 | **There are some limitations regarding the use of the Headless JS by this module that I should care about?** 87 | 88 | Yes, there are some nuances that you should concern about. For example, since Headless JS runs in a standalone "Task" you can't interact directly with it by the touch UI. 89 | For more information about using Headless JS in React Native, I suggest you take a look at the official documentation [here](https://reactnative.dev/docs/headless-js-android). 90 | 91 | *** 92 | 93 | **I keep receiving the warning `registerHeadlessTask or registerCancellableHeadlessTask called multiple times for the same key '${taskKey}'`, is that a problem?** 94 | 95 | No, this warning is here, where you can see that the task providers are stored in a set, and there's no way to delete them, so react is just complaining about the fact that we are overwriting it. 96 | 97 | *** 98 | 99 | **I allowed the notifications, and the module shows that the notifications are allowed but even then the notifications are not retrieved. There is anything else that I can do in this case?** 100 | 101 | It is known that old Android versions and device particularities sometimes require a reboot or even to be turned off completely and then turned on again to have the notification listener working properly. 102 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | apply plugin: "com.facebook.react" 3 | 4 | import com.android.build.OutputFile 5 | 6 | /** 7 | * This is the configuration block to customize your React Native Android app. 8 | * By default you don't need to apply any configuration, just uncomment the lines you need. 9 | */ 10 | react { 11 | /* Folders */ 12 | // The root of your project, i.e. where "package.json" lives. Default is '..' 13 | // root = file("../") 14 | // The folder where the react-native NPM package is. Default is ../node_modules/react-native 15 | // reactNativeDir = file("../node-modules/react-native") 16 | // The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen 17 | // codegenDir = file("../node-modules/react-native-codegen") 18 | // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js 19 | // cliFile = file("../node_modules/react-native/cli.js") 20 | 21 | /* Variants */ 22 | // The list of variants to that are debuggable. For those we're going to 23 | // skip the bundling of the JS bundle and the assets. By default is just 'debug'. 24 | // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants. 25 | // debuggableVariants = ["liteDebug", "prodDebug"] 26 | 27 | /* Bundling */ 28 | // A list containing the node command and its flags. Default is just 'node'. 29 | // nodeExecutableAndArgs = ["node"] 30 | // 31 | // The command to run when bundling. By default is 'bundle' 32 | // bundleCommand = "ram-bundle" 33 | // 34 | // The path to the CLI configuration file. Default is empty. 35 | // bundleConfig = file(../rn-cli.config.js) 36 | // 37 | // The name of the generated asset file containing your JS bundle 38 | // bundleAssetName = "MyApplication.android.bundle" 39 | // 40 | // The entry file for bundle generation. Default is 'index.android.js' or 'index.js' 41 | // entryFile = file("../js/MyApplication.android.js") 42 | // 43 | // A list of extra flags to pass to the 'bundle' commands. 44 | // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle 45 | // extraPackagerArgs = [] 46 | 47 | /* Hermes Commands */ 48 | // The hermes compiler command to run. By default it is 'hermesc' 49 | // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc" 50 | // 51 | // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map" 52 | // hermesFlags = ["-O", "-output-source-map"] 53 | } 54 | 55 | /** 56 | * Set this to true to create four separate APKs instead of one, 57 | * one for each native architecture. This is useful if you don't 58 | * use App Bundles (https://developer.android.com/guide/app-bundle/) 59 | * and want to have separate APKs to upload to the Play Store. 60 | */ 61 | def enableSeparateBuildPerCPUArchitecture = false 62 | 63 | /** 64 | * Set this to true to Run Proguard on Release builds to minify the Java bytecode. 65 | */ 66 | def enableProguardInReleaseBuilds = false 67 | 68 | /** 69 | * The preferred build flavor of JavaScriptCore (JSC) 70 | * 71 | * For example, to use the international variant, you can use: 72 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` 73 | * 74 | * The international variant includes ICU i18n library and necessary data 75 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that 76 | * give correct results when using with locales other than en-US. Note that 77 | * this variant is about 6MiB larger per architecture than default. 78 | */ 79 | def jscFlavor = 'org.webkit:android-jsc:+' 80 | 81 | /** 82 | * Private function to get the list of Native Architectures you want to build. 83 | * This reads the value from reactNativeArchitectures in your gradle.properties 84 | * file and works together with the --active-arch-only flag of react-native run-android. 85 | */ 86 | def reactNativeArchitectures() { 87 | def value = project.getProperties().get("reactNativeArchitectures") 88 | return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] 89 | } 90 | 91 | android { 92 | ndkVersion rootProject.ext.ndkVersion 93 | 94 | compileSdkVersion rootProject.ext.compileSdkVersion 95 | 96 | namespace "com.example" 97 | defaultConfig { 98 | applicationId "com.example" 99 | minSdkVersion rootProject.ext.minSdkVersion 100 | targetSdkVersion rootProject.ext.targetSdkVersion 101 | versionCode 2 102 | versionName "2.0" 103 | } 104 | 105 | splits { 106 | abi { 107 | reset() 108 | enable enableSeparateBuildPerCPUArchitecture 109 | universalApk false // If true, also generate a universal APK 110 | include (*reactNativeArchitectures()) 111 | } 112 | } 113 | signingConfigs { 114 | debug { 115 | storeFile file('debug.keystore') 116 | storePassword 'android' 117 | keyAlias 'androiddebugkey' 118 | keyPassword 'android' 119 | } 120 | } 121 | buildTypes { 122 | debug { 123 | signingConfig signingConfigs.debug 124 | } 125 | release { 126 | // Caution! In production, you need to generate your own keystore file. 127 | // see https://reactnative.dev/docs/signed-apk-android. 128 | signingConfig signingConfigs.debug 129 | minifyEnabled enableProguardInReleaseBuilds 130 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 131 | } 132 | } 133 | 134 | // applicationVariants are e.g. debug, release 135 | applicationVariants.all { variant -> 136 | variant.outputs.each { output -> 137 | // For each separate APK per architecture, set a unique version code as described here: 138 | // https://developer.android.com/studio/build/configure-apk-splits.html 139 | // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc. 140 | def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] 141 | def abi = output.getFilter(OutputFile.ABI) 142 | if (abi != null) { // null for the universal-debug, universal-release variants 143 | output.versionCodeOverride = 144 | defaultConfig.versionCode * 1000 + versionCodes.get(abi) 145 | } 146 | 147 | } 148 | } 149 | } 150 | 151 | dependencies { 152 | // The version of react-native is set by the React Native Gradle Plugin 153 | implementation("com.facebook.react:react-android") 154 | 155 | implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0") 156 | 157 | debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") 158 | debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { 159 | exclude group:'com.squareup.okhttp3', module:'okhttp' 160 | } 161 | 162 | debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") 163 | if (hermesEnabled.toBoolean()) { 164 | implementation("com.facebook.react:hermes-android") 165 | } else { 166 | implementation jscFlavor 167 | } 168 | } 169 | 170 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) 171 | -------------------------------------------------------------------------------- /package/android/src/main/java/com/lesimoes/androidnotificationlistener/RNNotification.java: -------------------------------------------------------------------------------- 1 | package com.lesimoes.androidnotificationlistener; 2 | 3 | import android.graphics.BitmapFactory; 4 | import android.service.notification.StatusBarNotification; 5 | import android.text.TextUtils; 6 | import android.app.Notification; 7 | import android.util.Log; 8 | import java.util.ArrayList; 9 | import android.content.pm.PackageManager; 10 | import android.content.res.Resources; 11 | import android.graphics.drawable.Drawable; 12 | import android.graphics.Bitmap; 13 | import java.io.ByteArrayOutputStream; 14 | import android.util.Base64; 15 | import android.content.Context; 16 | import java.lang.Exception; 17 | import android.graphics.drawable.Icon; 18 | import android.graphics.drawable.BitmapDrawable; 19 | 20 | public class RNNotification { 21 | private static final String TAG = "RNAndroidNotificationListener"; 22 | 23 | protected String app; 24 | protected String title; 25 | protected String titleBig; 26 | protected String text; 27 | protected String subText; 28 | protected String summaryText; 29 | protected String bigText; 30 | protected ArrayList<RNGroupedNotification> groupedMessages; 31 | protected String audioContentsURI; 32 | protected String imageBackgroundURI; 33 | protected String extraInfoText; 34 | protected String icon; 35 | protected String image; 36 | protected String time; 37 | protected String iconLarge; 38 | public RNNotification(Context context, StatusBarNotification sbn) { 39 | Notification notification = sbn.getNotification(); 40 | 41 | if (notification != null && notification.extras != null) { 42 | String packageName = sbn.getPackageName(); 43 | 44 | this.time = Long.toString(sbn.getPostTime()); 45 | this.app = TextUtils.isEmpty(packageName) ? "Unknown App" : packageName; 46 | this.title = this.getPropertySafely(notification, Notification.EXTRA_TITLE); 47 | this.titleBig = this.getPropertySafely(notification, Notification.EXTRA_TITLE_BIG); 48 | this.text = this.getPropertySafely(notification, Notification.EXTRA_TEXT); 49 | this.subText = this.getPropertySafely(notification, Notification.EXTRA_SUB_TEXT); 50 | this.summaryText = this.getPropertySafely(notification, Notification.EXTRA_SUMMARY_TEXT); 51 | this.bigText = this.getPropertySafely(notification, Notification.EXTRA_BIG_TEXT); 52 | this.audioContentsURI = this.getPropertySafely(notification, Notification.EXTRA_AUDIO_CONTENTS_URI); 53 | this.imageBackgroundURI = this.getPropertySafely(notification, Notification.EXTRA_BACKGROUND_IMAGE_URI); 54 | this.extraInfoText = this.getPropertySafely(notification, Notification.EXTRA_INFO_TEXT); 55 | this.iconLarge = this.getNotificationLargeIcon(context, notification); 56 | this.icon = this.getNotificationIcon(context, notification); 57 | this.image = this.getNotificationImage(notification); 58 | this.groupedMessages = this.getGroupedNotifications(notification); 59 | } else { 60 | Log.d(TAG, "The notification received has no data"); 61 | } 62 | } 63 | 64 | private String getPropertySafely(Notification notification, String propKey) { 65 | try { 66 | CharSequence propCharSequence = notification.extras.getCharSequence(propKey); 67 | 68 | return propCharSequence == null ? "" : propCharSequence.toString().trim(); 69 | } catch (Exception e) { 70 | Log.d(TAG, e.getMessage()); 71 | return ""; 72 | } 73 | } 74 | 75 | private ArrayList<RNGroupedNotification> getGroupedNotifications(Notification notification) { 76 | ArrayList<RNGroupedNotification> result = new ArrayList<RNGroupedNotification>(); 77 | 78 | try { 79 | CharSequence[] lines = notification.extras.getCharSequenceArray(Notification.EXTRA_TEXT_LINES); 80 | 81 | if (lines != null && lines.length > 0) { 82 | for (CharSequence line : lines) { 83 | if (!TextUtils.isEmpty(line)) { 84 | RNGroupedNotification groupedNotification = new RNGroupedNotification(this, line); 85 | result.add(groupedNotification); 86 | } 87 | } 88 | } 89 | 90 | return result; 91 | } catch (Exception e) { 92 | Log.d(TAG, e.getMessage()); 93 | return result; 94 | } 95 | } 96 | 97 | private String getNotificationIcon(Context context, Notification notification) { 98 | try { 99 | 100 | String result = ""; 101 | 102 | Icon iconInstance = notification.getSmallIcon(); 103 | Drawable iconDrawable = iconInstance.loadDrawable(context); 104 | Bitmap iconBitmap = ((BitmapDrawable) iconDrawable).getBitmap(); 105 | 106 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 107 | iconBitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream); 108 | 109 | result = Base64.encodeToString(outputStream.toByteArray(), Base64.DEFAULT); 110 | 111 | return TextUtils.isEmpty(result) ? result : "data:image/png;base64," + result; 112 | } catch (Exception e) { 113 | Log.d(TAG, e.getMessage()); 114 | return ""; 115 | } 116 | } 117 | 118 | 119 | private String getNotificationLargeIcon(Context context, Notification notification) { 120 | try { 121 | 122 | String result = ""; 123 | 124 | Icon iconInstance = notification.getLargeIcon(); 125 | Drawable iconDrawable = iconInstance.loadDrawable(context); 126 | Bitmap iconBitmap = ((BitmapDrawable) iconDrawable).getBitmap(); 127 | 128 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 129 | iconBitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream); 130 | 131 | result = Base64.encodeToString(outputStream.toByteArray(), Base64.DEFAULT); 132 | 133 | return TextUtils.isEmpty(result) ? result : "data:image/png;base64," + result; 134 | } catch (Exception e) { 135 | Log.d(TAG, e.getMessage()); 136 | return ""; 137 | } 138 | } 139 | 140 | private String getNotificationImage(Notification notification) { 141 | try { 142 | if (!notification.extras.containsKey(Notification.EXTRA_PICTURE)) return ""; 143 | 144 | Bitmap imageBitmap = (Bitmap) notification.extras.get(Notification.EXTRA_PICTURE); 145 | 146 | BitmapFactory.Options options = new BitmapFactory.Options(); 147 | options.inSampleSize = this.calculateInSampleSize(options, 100,100); 148 | options.inJustDecodeBounds = false; 149 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 150 | imageBitmap.compress(Bitmap.CompressFormat.JPEG, 30, outputStream); 151 | 152 | String result = Base64.encodeToString(outputStream.toByteArray(), Base64.DEFAULT); 153 | 154 | return TextUtils.isEmpty(result) ? result : "data:image/png;base64," + result; 155 | } catch (Exception e) { 156 | Log.d(TAG, e.getMessage()); 157 | return ""; 158 | } 159 | } 160 | 161 | public int calculateInSampleSize( 162 | BitmapFactory.Options options, int reqWidth, int reqHeight) { 163 | // Raw height and width of image 164 | final int height = options.outHeight; 165 | final int width = options.outWidth; 166 | int inSampleSize = 1; 167 | 168 | if (height > reqHeight || width > reqWidth) { 169 | 170 | final int halfHeight = height / 2; 171 | final int halfWidth = width / 2; 172 | 173 | // Calculate the largest inSampleSize value that is a power of 2 and keeps both 174 | // height and width larger than the requested height and width. 175 | while ((halfHeight / inSampleSize) >= reqHeight 176 | && (halfWidth / inSampleSize) >= reqWidth) { 177 | inSampleSize *= 2; 178 | } 179 | } 180 | 181 | return inSampleSize; 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | --------------------------------------------------------------------------------