Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
465 views
in Technique[技术] by (71.8m points)

Huawei SMS retriever api is not working and Huawei devices

I am trying to retrieve OTP in Huawei device. but it is not working.

I have created the app in Huawei developer console with all the requirements.

Below is the code i am using to retrieve the sms.

private fun initSmsManager() {

        val task = ReadSmsManager.start(this@MainActivity)

        task.addOnCompleteListener {

            if (task.isSuccessful) {
                // The service is enabled successfully. Continue with the process.
                Toast.makeText(this, "ReadSms service has been enabled.", Toast.LENGTH_LONG).show()
            } else
                Toast.makeText(this, "The service failed to be enabled.", Toast.LENGTH_LONG).show()
        }
        task.addOnSuccessListener(this, OnSuccessListener {
                if(task.isSuccessful){
                    Toast.makeText(this, "ReadSms service has been enabled.", Toast.LENGTH_LONG).show()
                    myReceiver = MyBroadcastReceiver();
                    val intentFilter = IntentFilter(READ_SMS_BROADCAST_ACTION)
                    registerReceiver(myReceiver, intentFilter)
                }
        })
        task.addOnFailureListener(this, OnFailureListener {
            Toast.makeText(this,it.message,Toast.LENGTH_SHORT).show();
        })
    }

Broadcast receiver

class MyBroadcastReceiver : BroadcastReceiver() {

    companion object {
        val TAG = MyBroadcastReceiver::class.java.simpleName
    }

    override fun onReceive(context: Context?, intent: Intent?) {

        val bundle = intent!!.extras
        if (bundle != null) {
            val status: Status? = bundle.getParcelable(ReadSmsConstant.EXTRA_STATUS)
            if (status?.statusCode == CommonStatusCodes.TIMEOUT) {

                // Service has timed out and no SMS message that meets the requirement is read. Service ended.
                // doSomethingWhenTimeOut()
            } else if (status?.statusCode == CommonStatusCodes.SUCCESS) {

                if (bundle.containsKey(ReadSmsConstant.EXTRA_SMS_MESSAGE)) {

                    // An SMS message that meets the requirement is read. Service ended.
                    //doSomethingWhenGetMessage(bundle.getString(ReadSmsConstant.EXTRA_SMS_MESSAGE))

                    bundle.getString(ReadSmsConstant.EXTRA_SMS_MESSAGE)?.let {

                        Log.d(TAG, it)

                        val local = Intent()
                        local.action = "service.to.activity.transfer"
                        local.putExtra("sms", it)
                        context!!.sendBroadcast(local)
                    }
                }
            }
        }
    }
}

Any help in this would be beneficial.

question from:https://stackoverflow.com/questions/65830443/huawei-sms-retriever-api-is-not-working-and-huawei-devices

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Please confirm the following points:

  1. Check whether the broadcast for receiving SMS verification codes is enabled. You can do that by performing breakpoint debugging or recording logs.
  2. Check whether the SMS message format meets the rules for automatically reading SMS messages.

For details,See Docs.

enter image description here

Check whether the hash_value field is correct.

  1. If no error occurs during the preceding check, could you pls provide a complete log trace then i will try to find out what can be wrong about this issue. :)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...