"
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/src/release/java/com/example/ReactNativeFlipper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Meta Platforms, Inc. and affiliates.
3 | *
4 | * 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 createViewManagers(ReactApplicationContext reactContext) {
15 | return Collections.emptyList();
16 | }
17 |
18 | @Override
19 | public List createNativeModules(ReactApplicationContext reactContext) {
20 | List 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 |
2 |
3 |
4 |
5 |
12 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/package/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Leandro Simões
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/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
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 | },
12 | "dependencies": {
13 | "@react-native-async-storage/async-storage": "^1.17.11",
14 | "react": "18.2.0",
15 | "react-native": "0.71.0",
16 | "react-native-android-notification-listener": "../package"
17 | },
18 | "devDependencies": {
19 | "@babel/core": "^7.12.9",
20 | "@babel/preset-env": "^7.14.0",
21 | "@babel/runtime": "^7.12.5",
22 | "@react-native-community/eslint-config": "^3.0.0",
23 | "@tsconfig/react-native": "^2.0.2",
24 | "@types/jest": "^29.2.1",
25 | "@types/react": "^18.0.24",
26 | "@types/react-test-renderer": "^18.0.0",
27 | "babel-jest": "^29.2.1",
28 | "eslint": "^8.19.0",
29 | "jest": "^29.2.1",
30 | "metro-react-native-babel-preset": "0.73.5",
31 | "prettier": "^2.4.1",
32 | "react-test-renderer": "18.2.0",
33 | "typescript": "4.8.4"
34 | },
35 | "jest": {
36 | "preset": "react-native"
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/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!
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
26 | * [GitHub Sponsor Page](https://github.com/sponsors/leandrosimoes)
27 | * [Buy Me A Coffee](https://www.buymeacoffee.com/leandrosimoes)
28 | * [More Info](https://lesimoes.dev)
--------------------------------------------------------------------------------
/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 "example";
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 |
--------------------------------------------------------------------------------
/package/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
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 | }
--------------------------------------------------------------------------------
/example/index.tsx:
--------------------------------------------------------------------------------
1 | import { AppRegistry } from 'react-native'
2 | import { RNAndroidNotificationListenerHeadlessJsName } from 'react-native-android-notification-listener'
3 |
4 | import AsyncStorage from '@react-native-async-storage/async-storage'
5 |
6 | import { name as appName } from './app.json'
7 | import App from './src/App'
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