shounakmulay / Telephony

Flutter plugin for telephony features like query device sms directory, listen for incoming messages, retrieve various network parameters, etc.
https://telephony.shounakmulay.dev
MIT License
138 stars 126 forks source link

PlatformException - failed_to_fetch_sms #146

Open chavdardonchev opened 2 years ago

chavdardonchev commented 2 years ago

Hi, I'm getting this error whenever I try to send an SMS. I tried with both Flutter 2.10.5 and 3.0.1

_telephony.sendSms(to: '00359882077170', message: 'Hello!');

E/flutter (  975): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(failed_to_fetch_sms, Flutter Telephony: Error getting SmsManager, null, null)
E/flutter (  975): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (  975): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
E/flutter (  975): <asynchronous suspension>
E/flutter (  975): #2      Telephony.sendSms (package:telephony/telephony.dart:321:5)
E/flutter (  975): <asynchronous suspension>
E/flutter (  975): 

It's always there.

swayamshreemohanty commented 2 years ago

Same Error.

swayamshreemohanty commented 2 years ago

@chavdardonchev , I think in the telephony: ^0.2.0, there is some error. You may try the telephony: ^0.1.4. It's worked for me.

chavdardonchev commented 2 years ago

@swayamshreemohanty I tried it. It's impossible to build the app with 0.1.4. I should probably downgrade the Flutter version quite a lot, which is very undesirable in my case.

swayamshreemohanty commented 2 years ago

@chavdardonchev , just change the telephony version name in the pubspec to 0.1.4. . Umm, is there any issue to change the version from 0.2.0 to 0.1.4?

chavdardonchev commented 2 years ago

@swayamshreemohanty Yes, I can't even run the app if I switch to 0.1.4. I get nasty errors at build time. 01.4 was released 1 year ago, which is quite long time ago and will probably work with Flutter 2.5 or maybe 2.8?. I'm with Flutter 2.10 and just switched to 3.0.1, hoping 0.2.0 will work (it was released after Fluter 3 with fixes for it). But 0.2.0 doesn't work with Flutter 3 either, because of that "failed_to_fetch_sms" exception.

swayamshreemohanty commented 2 years ago

@chavdardonchev , in my case, I'm using Flutter 3.0.0 with telephony 0.1.4 . It's working fine. Hope your problem will solve soon.

dibyanshu-mohanty commented 2 years ago

@swayamshreemohanty You aren't getting any error while using Flutter 3.0.0 with telephony 0.1.4 ?

swayamshreemohanty commented 2 years ago

Yea it's working properly @dibyanshu-mohanty Here is my project link: https://github.com/swayamshreemohanty/flutter_send_sms

dibyanshu-mohanty commented 2 years ago

Would you mind sharing th telephony send sms function @swayamshreemohanty

swayamshreemohanty commented 2 years ago

Here are the 2 types of functions before the build method: https://github.com/swayamshreemohanty/flutter_send_sms/blob/master/lib/sms_send_screen.dart

shounakmulay commented 2 years ago

@chavdardonchev Would you please tell me the minSdk and compileSdk versions?

dibyanshu-mohanty commented 2 years ago

@shounakmulay minSdk : 23 and default targetSdk versions

chavdardonchev commented 2 years ago

@shounakmulay Yes, it is: minSdkVersion 23 targetSdkVersion 32

ravivr-dev commented 2 years ago

await _telephony.sendSms( to: element.contact.phones![0].value!, message: message.body ?? "", isMultipart: true);

Getting same issue for android version 9 and device Redmi note 6 pro. but the same code is working fine for android version 12, device Samsung G A52. @shounakmulay any help??

Lorelyv commented 2 years ago

telephony.sendSms( to: _reciever.text, message: 'Key: ' + encryption('Configuration|' + _reciever.text + '|' + hasher('Configuration|' + _reciever.text + phoneID)), statusListener: listener);

android version 12 with the latest update flutter 0.2.0 is perfectly fine but if i run my app with lower android version with flutter 0.2.0 there's an error with the failed_to_fetch_sms. When i downgrade to flutter 0.1.4 running on an android version lower than 12 is perpectly fine but on android 12 with flutter 0.1.4 will have the error this time.

minSdkVersion 23 targetSdkVersion 31

worldwidee commented 2 years ago

any update?

mahaseth commented 2 years ago

need fix of this issue, any update ?

mahaseth commented 2 years ago

@shounakmulay any update on this.

v1ncere commented 2 years ago

telephony.sendSms( to: _reciever.text, message: 'Key: ' + encryption('Configuration|' + _reciever.text + '|' + hasher('Configuration|' + _reciever.text + phoneID)), statusListener: listener);

android version 12 with the latest update flutter 0.2.0 is perfectly fine but if i run my app with lower android version with flutter 0.2.0 there's an error with the failed_to_fetch_sms. When i downgrade to flutter 0.1.4 running on an android version lower than 12 is perpectly fine but on android 12 with flutter 0.1.4 will have the error this time.

minSdkVersion 23 targetSdkVersion 31

153 fix controller error, this solves my problem

suhardik commented 2 years ago

hope this help 🙂 https://github.com/shounakmulay/Telephony/issues/149#issuecomment-1212695720