Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Timeout error. Listener never returns event message from sms. #4

Closed
Technaur opened this issue Feb 20, 2019 · 32 comments
Closed

Timeout error. Listener never returns event message from sms. #4

Technaur opened this issue Feb 20, 2019 · 32 comments
Labels
question Questions about the project

Comments

@Technaur
Copy link

Technaur commented Feb 20, 2019

Environment

  • React Native Version: 58.3
  • Platform: Android
  • Device: Simulator
  • OS Version: 9
  • react-native-sms-retriever version
  • Devtools: Android Studio Version
  • Build Tools Version (Android only)

Description

I trigger the _onSmsListenerPressed function with a button. "const registered = await SmsRetriever.startSmsRetriever()" comes back as true. I then send a correctly formatted sms from the Extended Controls panel. After a few minutes I am greeted with "Timeout error."

The sms content never gets returned in the listener.

Solution (Edit)

Just replace com.sms_listener with your own package name.
The default -alias for the debug keystore will always be androiddebugkey

keytool -exportcert -alias androiddebugkey -keystore '~\.android\debug.keystore' | xxd -p | tr -d "[:space:]" | echo -n <<<com.sms_listener>>> cat | sha256sum | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11

If you are using the debug keystore like me, it will ask for a password after you run the above command.
The default password is: android

A string will then be generated, something like this: gaMzAZ+vMRr

@Bruno-Furtado
Copy link
Owner

Bruno-Furtado commented Feb 20, 2019

@Technaur, there are some rules for reading the content of the message.
You can get more information here.

@Bruno-Furtado Bruno-Furtado added the question Questions about the project label Feb 20, 2019
@Technaur
Copy link
Author

@Bruno-Furtado I did follow those guidelines. I got my sms to look like this.

<#> Company OTP: SABED7 MjcTZmXXYWY

@Bruno-Furtado
Copy link
Owner

@Technaur, I'm not sure if it's the problem, but could you try to leave the hash on a new line?

@Technaur
Copy link
Author

This is actually what it looked like from the extended controls panel.

image

I might not have had a new line character in there... It just appeared like there was a new line with the wrapping of the word. I will test again and get back to you shortly.

@Technaur
Copy link
Author

@Bruno-Furtado So this time I made sure that I have a newline character.

My Code.

import SmsRetriever from "react-native-sms-retriever"
...
  _onSmsListenerPressed = async () => {
    try {
      const registered = await SmsRetriever.startSmsRetriever()
      console.log("Response: ", registered)
      if (registered) {
        SmsRetriever.addSmsListener(event => {
          console.log("MSG:", event.message)
          SmsRetriever.removeSmsListener()
        })
      }
    } catch (error) {
      console.log("ERROR", error)
    }
  }

Registered does come back on true, then after that I send the sms like in the image above. But my .addSmsListener is never triggered.

@Bruno-Furtado
Copy link
Owner

@Technaur, can you debug the Java code on Android Studio? so we can get more details...

@ranjithkumar8352
Copy link

Same issue here! I'm testing on Android 7.0 emulator with google play services

@mpraki
Copy link

mpraki commented Mar 5, 2019

@Technaur @ranjithkumar8352 are you building your apk with the same keys you used to generate the hash? If its debug build and your hash is release apk's, Android system won't read the SMS.

Make sure you are building the APK with the same key which is used to generate the hash.

@srivatsav
Copy link

srivatsav commented Mar 6, 2019

@Technaur are you generating the hashkey using your android debug keystore. The debug keystore can be found in ~/.android/debug.keystore . The password prompted for should be android (case sensitive)
This worked for me. Hopefully, should work for you as well.

@Technaur
Copy link
Author

Technaur commented Mar 7, 2019

@mpraki @srivatsav Turns out I was generating the hash completely wrong. I followed your advice by running this command.

keytool -exportcert -alias androiddebugkey -keystore '~\.android\debug.keystore' | xxd -p | tr -d "[:space:]" | echo -n <<<com.sms_listener>>>cat| sha256sum | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11

That generated the correct 11 character hash for me. Thanks for the help :)

It is working now.

@shehzadosama
Copy link

I have used your solution in which you highlighted that:

  1. Just replace com.sms_listener with your own package name.
  2. Execute this command but i get hash string without any password prompt: keytool -exportcert -alias androiddebugkey -keystore '~.android\debug.keystore' | xxd -p | tr -d "[:space:]" | echo -n <<<com.sms_listener>>> cat | sha256sum | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11
  3. This is the message format i am using but my app is not able to listen this message and it just giving Timeout response error after couple of seconds. <#> Your ExampleApp code is: 123ABC78
    +3qf7l3o1M4

Please suggest me how can I tackle this issue.
Your consideration will be appreciable.
Thank you.

Environment

  • React Native Version: 58.3
  • Platform: Android
  • Device: Simulator
  • OS Version: 9
  • react-native-sms-retriever version
  • Devtools: Android Studio Version
  • Build Tools Version (Android only)

Description

I trigger the _onSmsListenerPressed function with a button. "const registered = await SmsRetriever.startSmsRetriever()" comes back as true. I then send a correctly formatted sms from the Extended Controls panel. After a few minutes I am greeted with "Timeout error."

The sms content never gets returned in the listener.

Solution (Edit)

Just replace com.sms_listener with your own package name.
The default -alias for the debug keystore will always be androiddebugkey

keytool -exportcert -alias androiddebugkey -keystore '~\.android\debug.keystore' | xxd -p | tr -d "[:space:]" | echo -n <<<com.sms_listener>>> cat | sha256sum | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11

If you are using the debug keystore like me, it will ask for a password after you run the above command.
The default password is: android

A string will then be generated, something like this: gaMzAZ+vMRr

@Rushi271193
Copy link

Hey I have tried all the answers give n above. Nothing works for me. My evenlistener never gets triggered.

@ranjithkumar8352
Copy link

This issue happens if the hash is wrong. I tried many suggested methods to generate hash but all of them were wrong. Maybe I did something wrong in the hash generation process. Finally, I had to use the getHash() method from another library to get the right hash - https://github.com/Rajat421/react-native-sms-retriever-api
Note: You can't install this library and above-mentioned library at the same time because of some dependency clash.

@shehzadosama
Copy link

@ranjithkumar8352 can you please share the block of code that how you used the getHash() method? I am facing error while calling getHash() method in componentDidMount()

I am trying to use in this way:
RNSmsRetriever.getHash().then(res => { console.log("GET HASH RES : ", res) }).catch(err => { console.log("GET HASH ERR : ", err) })

Facing this error:
TypeError: TypeError: undefined is not a function (evaluating '_reactNativeSmsRetrieverApi.default.getHash()')

UlJMUg

@Rushi271193
Copy link

@ranjithkumar8352 thanks for your input. That should solve for development . But what about the release variant. How do we get the correct signature

@ranjithkumar8352
Copy link

ranjithkumar8352 commented Jul 26, 2019

@ranjithkumar8352 can you please share the block of code that how you used the getHash() method? I am facing error while calling getHash() method in componentDidMount()

I am trying to use in this way:
RNSmsRetriever.getHash().then(res => { console.log("GET HASH RES : ", res) }).catch(err => { console.log("GET HASH ERR : ", err) })

Facing this error:
TypeError: TypeError: undefined is not a function (evaluating '_reactNativeSmsRetrieverApi.default.getHash()')

Make sure that you completely remove this library and install that library properly. This error happens when this library is still linked.

@ranjithkumar8352
Copy link

@Rushi271193 I do the same for release variant as well. I build the app for release variant once and note down the hash.
@shehzadosama Here's the code I use to capture the hash.

getHash = async () => {
    const hash = await RNSmsRetriever.getHash();
    const headers = new Headers();
    headers.append("Content-Type", "application/json");

    const body = { hash: hash };

    const options = {
      method: "POST",
      headers,
      mode: "cors",
      body: JSON.stringify(body)
    };

    fetch("<requestbin.com url>", options);
  };

@Rushi271193
Copy link

@ranjithkumar8352 I tried doing the same but the key generated for the signed apk doesn't work

@Rushi271193
Copy link

I am actually just using the signature class from java as both the libraries cannot be used together. I call the signature class in the Main activity and i receive a hash but it does not work. Can you help me out here

@ranjithkumar8352
Copy link

@Rushi271193 You might be missing something with the signature class. I'm not sure about that. Why don't you just uninstall this library, install the other one and get hash? It just takes 5 minutes

@sagarhudge
Copy link

@mpraki how to generate hex for release with keystore path and on addSmslistener I am getting time out exception added on componentDidMount

@mpraki
Copy link

mpraki commented Sep 24, 2019 via email

@sagarhudge
Copy link

sagarhudge commented Sep 25, 2019

@mpraki @Bruno-Furtado @gitter-badger @ranjithkumar8352
This is for debug I am using -I have executed this command in C:\Program Files\Java\jre1.8.0_191\bin not asked for password.

keytool -exportcert -alias androiddebugkey -keystore '~\.android\debug.keystore' | xxd -p | tr -d "[:space:]" | echo -n com.opick.app cat | sha256sum | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11

For release same command need to be executed? like bellow
keytool -exportcert -alias releaseappkey -keystore '~\.android\release_opick.keystore' | xxd -p | tr -d "[:space:]" | echo -n com.opick.app cat | sha256sum | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11

Please help ?

@sagarhudge
Copy link

@shehzadosama can you tell me in which place you executed above command and also how you did for release and how you have give release keystore path

@sagarhudge
Copy link

@mpraki @Bruno-Furtado @gitter-badger @ranjithkumar8352
The hash key added in sms will always display or we can hide

@ranjithkumar8352
Copy link

@sagarhudge Hash is always displayed in the SMS

@kesha-antonov
Copy link

Hi
I wrote ruby script to get correct hash for SMS https://github.com/kesha-antonov/android-sms-verification-hash
Maybe it'll help future readers like me

@khaja-nizamuddin1
Copy link

khaja-nizamuddin1 commented Sep 3, 2020

When I run this command to fetch my hash, it returns the following error:
keytool -exportcert -alias androiddebugkey -keystore '~\.android\debug.keystore' | xxd -p | tr -d "[:space:]" | echo -n com.opick.app cat | sha256sum | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11

Capturesss

Note: app1sms.keystore >>> app1sms is the name I gave while creating keystore for this app
Any help?

@shehzadosama
Copy link

When I run this command to fetch my hash, it returns the following error:
keytool -exportcert -alias androiddebugkey -keystore '~\.android\debug.keystore' | xxd -p | tr -d "[:space:]" | echo -n com.opick.app cat | sha256sum | tr -d "[:space:]-" | xxd -r -p | base64 | cut -c1-11

Capturesss

Note: app1sms.keystore >>> app1sms is the name I gave while creating keystore for this app
Any help?

@khaja-nizamuddin1 check your command you are running on command prompt. It contains echo -n <<<com.sms_listener>>> instead of your app package name that is com.opick.app

@stepdi
Copy link

stepdi commented Nov 1, 2020

On a Mac I could get this command to work properly:

echo -n "com.yourappname" `keytool -exportcert -keystore ./android/app/debug.keystore -alias androiddebugkey | xxd -p | tr -d "[:space:]"` | sha256sum | xxd -r -p | base64 | cut -c1-11

Now I've got hash and it is working. I see my message in my app.
I also needed to install coreutils (brew install coreutils) in order to get sha256sum to work

@thiago-soliveira
Copy link

On a Mac I could get this command to work properly:

echo -n "com.yourappname" `keytool -exportcert -keystore ./android/app/debug.keystore -alias androiddebugkey | xxd -p | tr -d "[:space:]"` | sha256sum | xxd -r -p | base64 | cut -c1-11

Now I've got hash and it is working. I see my message in my app. I also needed to install coreutils (brew install coreutils) in order to get sha256sum to work

This is the only way that worked for me

@Hasham24
Copy link

On a Mac I could get this command to work properly:

echo -n "com.yourappname" `keytool -exportcert -keystore ./android/app/debug.keystore -alias androiddebugkey | xxd -p | tr -d "[:space:]"` | sha256sum | xxd -r -p | base64 | cut -c1-11

Now I've got hash and it is working. I see my message in my app. I also needed to install coreutils (brew install coreutils) in order to get sha256sum to work

This command generates the hash key but the OTP is never read, it's working with debug but not with the release.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Questions about the project
Projects
None yet
Development

No branches or pull requests