Reputation:
I'm building an app and I need to detect all phone calls, assuming my app is always in the background.
I've looked over react-native-call-detection
package from
https://www.npmjs.com/package/react-native-call-detection.
The question is, how do I make the listener global, meaning that it doesn't matter in which screen the user is or if the app is in background, how to detect incoming calls?
Upvotes: 3
Views: 2661
Reputation: 165
You could create a new class for the listener, than make a new class element in every screen. For example you create a class like, phoneCallListener, this class has a constructor, and a function which starts the detection, which name would be, startDetection(); Then in every activity you create a new element, like phoneCallListener myListener = new phoneCallListener(); , then you call the method and you are read, myListener.startDetection();
Another soluton is to make only one screen with fragments, so you will have one activity which's screen can change, so there will be a global class, and a fragment class.
Upvotes: 2