"
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 | * 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) 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 |
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 | }
--------------------------------------------------------------------------------
/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] "
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 |
2 |
16 |
21 |
22 |
23 |
32 |
33 |
34 |
35 |
36 |
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 -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 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(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 |
38 | //
39 | //
55 | // Setting
56 | //
57 |
58 |
59 | //
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 getPackages() {
24 | @SuppressWarnings("UnnecessaryLocalVariable")
25 | List 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 = ({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 |
23 |
24 | Faq Question
25 | ask away the question you want
26 |
33 |
34 | Submit Request
35 |
36 |
37 | { visibleSettings &&
38 | Open Configs
39 | }
40 |
41 |
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 | * 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 . 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