Telephony icon indicating copy to clipboard operation
Telephony copied to clipboard

PlatformException - failed_to_fetch_sms

Open chavdardonchev opened this issue 2 years ago • 20 comments

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.

chavdardonchev avatar May 22 '22 15:05 chavdardonchev

Same Error.

swayamshreemohanty avatar May 22 '22 17:05 swayamshreemohanty

@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.

swayamshreemohanty avatar May 22 '22 17:05 swayamshreemohanty

@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.

chavdardonchev avatar May 22 '22 17:05 chavdardonchev

@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?

swayamshreemohanty avatar May 22 '22 17:05 swayamshreemohanty

@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.

chavdardonchev avatar May 22 '22 18:05 chavdardonchev

@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.

swayamshreemohanty avatar May 22 '22 18:05 swayamshreemohanty

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

dibyanshu-mohanty avatar May 23 '22 16:05 dibyanshu-mohanty

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

swayamshreemohanty avatar May 23 '22 16:05 swayamshreemohanty

Would you mind sharing th telephony send sms function @swayamshreemohanty

dibyanshu-mohanty avatar May 23 '22 17:05 dibyanshu-mohanty

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

swayamshreemohanty avatar May 23 '22 17:05 swayamshreemohanty

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

shounakmulay avatar May 23 '22 17:05 shounakmulay

@shounakmulay minSdk : 23 and default targetSdk versions

dibyanshu-mohanty avatar May 24 '22 06:05 dibyanshu-mohanty

@shounakmulay Yes, it is: minSdkVersion 23 targetSdkVersion 32

chavdardonchev avatar May 24 '22 12:05 chavdardonchev

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??

ravivr-dev avatar May 30 '22 06:05 ravivr-dev

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

Lorelyv avatar May 31 '22 03:05 Lorelyv

any update?

worldwidee avatar Jun 14 '22 12:06 worldwidee

need fix of this issue, any update ?

mahaseth avatar Jun 19 '22 19:06 mahaseth

@shounakmulay any update on this.

mahaseth avatar Jun 22 '22 07:06 mahaseth

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

v1ncere avatar Sep 02 '22 03:09 v1ncere

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

suhardik avatar Sep 06 '22 10:09 suhardik