hanatharesh2712 / ionic-native-sms-retriever-plugin-master

Cross-platform plugin for Cordova / PhoneGap to Retrieve SMS. Available for Android.
27 stars 18 forks source link

Cannot read SMS received on mobile #3

Closed supriyamalusare closed 5 years ago

supriyamalusare commented 5 years ago

Hi , I have installed cordova-plugin-sms-retriever-manager plugin in ionic project to read SMS received on mobile. Below code I have added to read SMS -

window['cordova']['plugins']['smsRetriever']['startWatching']( // the first callback is the success callback. We got back the native code’s result here. (result) => { alert('Message' + result); }, // the second is the error callback where we get back the errors (err) => { alert("Error = " + err) } );

But when I received any message on device , the above code cannot detect it. After sometimes it shows error TIMEOUT.

hanatharesh2712 commented 5 years ago

@supriyamalusare Are you sending SMS with your APP hash code? the format of SMS must be same as suggested here: https://developers.google.com/identity/sms-retriever/verify#1_construct_a_verification_message

supriyamalusare commented 5 years ago

@hanatharesh2712 I am sending message from another mobile with below message = <#> Your ExampleApp code is: 123ABC78 FA+9qCX9VSu

hanatharesh2712 commented 5 years ago

@supriyamalusare You have to generate your APP hash code and then replace "FA+9qCX9VSu" with your APP hash. To generate your APP hash: https://developers.google.com/identity/sms-retriever/verify#computing_your_apps_hash_string

OR

There is another way is to install another plugin as below and you will get your APP hash in toast message.

ionic cordova plugin add https://github.com/hanatharesh2712/ionic-native-sms-retriever-plugin-master-hash.git

You have to call below function to get the hash code in toast message:

window['cordova']['plugins']['smsRetriever']['startWatching'](
// the first callback is the success callback. We got back the native code’s result here.
(result) => {
alert('Message' + result);
},
// the second is the error callback where we get back the errors
(err) => {
alert("Error = " + err)
}
);
supriyamalusare commented 5 years ago

@hanatharesh2712 I have installed another plugin - ionic cordova plugin add https://github.com/hanatharesh2712/ionic-native-sms-retriever-plugin-master-hash.git. Also On one button click I have added above mentioned code but I am not receiving any toast of hashcode . After some time I am receiving Error message i.e. TIMEOUT

hanatharesh2712 commented 5 years ago

@supriyamalusare Try to remove the platform and add it again. and make sure that "ionic-native-sms-retriever-plugin-master" should not be there. after getting hash you can add this plugin and remove hash plugin(ionic-native-sms-retriever-plugin-master-hash).

supriyamalusare commented 5 years ago

@hanatharesh2712 I have removed platform and added again. And after that I received 11 characters hash code. Thank you so much.

I have uninstalled hash plugin and install plugin with command ionic cordova plugin add cordova-plugin-sms-retriever-manager@latest.

I have called below code on one button click but I am not able to read message received on device -

window['cordova']['plugins']['smsRetriever']['startWatching']( // the first callback is the success callback. We got back the native code’s result here. (result) => { alert('Message' + result); }, // the second is the error callback where we get back the errors (err) => { alert(err); } );

I am testing it on Debug unsigned apk. Does It require signed APK ?

hanatharesh2712 commented 5 years ago

@supriyamalusare Are you sending SMS with your hash code with below format?

<#> Your ExampleApp code is: 123ABC78 YOUR_HASH_CODE_HERE

e.g: <#> Your ExampleApp code is: 123ABC78 FA+9qCX9VSu

supriyamalusare commented 5 years ago

@hanatharesh2712 Yes. I am sending SMS with below format - <#> Your ExampleApp code is: 123ABC78 MY_HASH_CODE_HERE

hanatharesh2712 commented 5 years ago

@supriyamalusare What do you get response from "window['cordova']['plugins']['smsRetriever']['startWatching']" function? If you do not recieve any SMS within 5 min then it will return "TIMEOUT" message. Do you get this?

For now, You can test in an emulator and send SMS from emulator itself.

supriyamalusare commented 5 years ago

@hanatharesh2712 I am not receiving any response from "window['cordova']['plugins']['smsRetriever']['startWatching']" function. But after some time it is showing error message TIMEOUT. I am using Mac book pro.

I have tested it on Signed APK. But still facing this issue

hanatharesh2712 commented 5 years ago

@supriyamalusare It seems your hash code may be wrong. Can you share your device log? It may help to resolve this. if you are testing with signed APK then you need to generate your hash with that certificate.

supriyamalusare commented 5 years ago

@hanatharesh2712 Ok. Actually I am using hash code of unsigned apk. I will check it with signed apk and update you. Thank you so much.

supriyamalusare commented 5 years ago

@hanatharesh2712 I have used signed apk hash code. And it is working and now I am able to read message text. Thank you so much.

bhavik3184 commented 2 years ago

@supriyamalusare It seems your hash code may be wrong. Can you share your device log? It may help to resolve this. if you are testing with signed APK then you need to generate your hash with that certificate.

HASH Key changes when the APK is signed and otherwise. Thus for Production APK the HASH will be different - Please note, case save a lot of time if not known.