nativescript自动短信监听| android和ios

sczxawaw  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(212)

我正在尝试实现一个sms接收器,它将在android和ios上工作,因为我正在nativescript框架上开发,这需要自动侦听包含otp的sms,类似于whatsapp的功能。
我已经尝试了以下插件:nativescript sms receiver,这主要用于android实现,而且似乎无法正常运行。
ListingClass.ts:

public ngOnInit() {
  console.log("In OTP");
  // register Sms Listener to get SMS callbacks
  SmsReceiver.getInstance().registerListeners(
      function () {
        console.log("Listening started");
        // onSMSReceiverStarted
      }.bind(this),
      function (exception) {
        console.log("Listening failed");
        console.log(exception)
        // onSMSReceiverFailed
      }.bind(this),
      function (message) {
        // onSMSReceived
        // handle sms here
        // deregister Sms Listener to avoid invalid operations
        console.log("recieved");
        SmsReceiver.getInstance().deregisterListeners();
      }.bind(this),
      function () {
        // onSMSReceiverTimeOut
        console.log("listening failed on OTP");
      }.bind(this)
  );

  // start sms receiver for single message
  SmsReceiver.getInstance().startReceiver();
}

androidmanifest.xml:

<receiver android:name="com.pravinkumarputta.android.smsreceiver.SMSBroadcastReceiver" android:exported="true">
    <intent-filter>
        <action android:name="com.google.android.gms.auth.api.phone.SMS_RETRIEVED"/>
    </intent-filter>
</receiver>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题