From a31f0cb040ad78f9f4bf5952b0249f3fb92ac104 Mon Sep 17 00:00:00 2001 From: Maike Nunes Date: Mon, 11 Jan 2021 15:36:31 -0300 Subject: [PATCH 1/2] adding react native import lib class --- .../CallDetectionReactPackage.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 android/src/main/java/com/pritesh/calldetection/CallDetectionReactPackage.java diff --git a/android/src/main/java/com/pritesh/calldetection/CallDetectionReactPackage.java b/android/src/main/java/com/pritesh/calldetection/CallDetectionReactPackage.java new file mode 100644 index 000000000..7221df402 --- /dev/null +++ b/android/src/main/java/com/pritesh/calldetection/CallDetectionReactPackage.java @@ -0,0 +1,31 @@ +package com.pritesh.calldetection; + +import com.facebook.react.ReactPackage; +import com.facebook.react.bridge.JavaScriptModule; +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.uimanager.ViewManager; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class CallDetectionReactPackage implements ReactPackage { + + // Deprecated RN 0.47 + public List> createJSModules() { + return Collections.emptyList(); + } + + @Override + public List createViewManagers(ReactApplicationContext reactContext) { + return Collections.emptyList(); + } + + @Override + public List createNativeModules( + ReactApplicationContext reactContext) { + List modules = new ArrayList<>(); + modules.add(new CallDetectionManagerModule(reactContext)); + return modules; + } +} From c8d300507c38bfb6c40005424b2cc24b5e67ef83 Mon Sep 17 00:00:00 2001 From: Maike Nunes Date: Mon, 11 Jan 2021 18:24:36 -0300 Subject: [PATCH 2/2] improving setup doc --- README.md | 17 +++++++++++++++-- .../CallDetectionReactPackage.java | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d25e88006..938cc2a1b 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,21 @@ yarn add react-native-call-detection ``` -### For Android:- -Autolinking should work without manual changes +### For Android: + +In `android/app/src/main/java/.../MainApplication.java`: + +```java +import com.pritesh.calldetection.CallDetectionReactPackage; // Add this import line +//... + +private static List getPackages() { + return Arrays.asList( + new MainReactPackage(), + new CallDetectionReactPackage() // Add this line + ); +} +``` ## Usage There are different hooks that you may get depending on the platform. Since for android you could also request the package to provide you with phone number of the caller, you will have to provide the necessary request message and the corresponding error callback. The package will request for `READ_PHONE_STATE` permission in android. diff --git a/android/src/main/java/com/pritesh/calldetection/CallDetectionReactPackage.java b/android/src/main/java/com/pritesh/calldetection/CallDetectionReactPackage.java index 7221df402..e82a15880 100644 --- a/android/src/main/java/com/pritesh/calldetection/CallDetectionReactPackage.java +++ b/android/src/main/java/com/pritesh/calldetection/CallDetectionReactPackage.java @@ -11,6 +11,10 @@ public class CallDetectionReactPackage implements ReactPackage { + public CallDetectionReactPackage() { + + } + // Deprecated RN 0.47 public List> createJSModules() { return Collections.emptyList();