1

I am working on an app like the true caller. I want to listen only to that notification that is coming from the default phone dialer app. I Have checked this, this but didn't get the right answer. My task is I want to open a dialogue box only where there is an incoming caller. I tried the following code if the package name has the string dialer through the following code.

  const handleNotificationReceived = notification => {
      if(notification.app.substr(notification.app.length - 6) === 'dialer'){
          setNum(notification.title)
          onAdd(num);
          setLastNotification(notification);
        }
  };

I need this on android 5 and higher. Also, I am using React Native so if there is any solution in react native or android is highly appreciated.

  • You can't get notification from other apps. It would be extremely insecure if you could- you could grab text of incoming SMS and other messages, which would be a major problem with SMS security codes. If you want to know when an incoming phone call happens, there's other ways to do that. See https://stackoverflow.com/questions/15563921/how-to-detect-incoming-calls-in-an-android-device – Gabe Sechan Dec 28 '20 at 06:54
  • react-native-android-notification-listener we can listen to all notifications. By this, I am getting notifications from all the apps even Whatsapp, and can read their text. –  Dec 28 '20 at 07:15
  • That should only work if the user explicitly enables that permission for your app. Which no user with any sense would. The method in the post I linked to doesn't need such scary permissions, works with any dialer app, and isn't going to have false positives from other notifications by the dialer (mine is always asking me to rate call quality). Doing this via notifications, if you can even get a user to allow it, is the wrong way. – Gabe Sechan Dec 28 '20 at 07:30
  • SIr @GabeSechan I have searched for this problem. I got the mobile number for the phone call state from the PERMISSION PHONECALLSTATE up to android 7.on android 8,9,10 I didn't show the mobile number. I got an empty field. –  Dec 28 '20 at 13:18

0 Answers0