Comments (13)
@shounakmulay they are about sending SMS in background. We also encounter this problem. We have firebase configured, and when receive background notification we want to send SMS.
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
final Telephony telephony = Telephony.instance;
@override
void initState() {
initFirebase();
super.initState();
}
initFirebase() async {
await telephony.requestPhoneAndSmsPermissions;
_firebaseMessaging.requestNotificationPermissions();
_firebaseMessaging.subscribeToTopic('verify');
_firebaseMessaging.configure(
onBackgroundMessage: _onBackgroundMessage,
onMessage: (Map<String, dynamic> notification) async {
String phone = notification['data']['phone'];
String message = notification['data']['body'];
telephony.sendSms(to: phone, message: message);
},
);
}
onMessage
fires only when app is open, and it works. But on onBackgroundMessage
it throws above MissingPluginException
error.
Future<dynamic> _onBackgroundMessage(
Map<String, dynamic> notification,
) async {
final String phone = notification['data']['phone'];
final String message = notification['data']['body'];
Telephony.instance.sendSms(to: phone, message: message);
return Future<void>.value();
}
from telephony.
@kakajansh Thanks for the explanation.
I guess I had an incorrect understand of the problem.
Will take a look and update here.
from telephony.
I'm also getting this exception when using this package with WorkManager and AndroidAlarmManager ):
from telephony.
Hey @cuongdl @dinahapuque
I was not able to reproduce this issue.
I could correctly receive SMS in background on an emulator as well as on a physical device.
Could you please provide a reproducible example that I can look into?
from telephony.
Using AndroidAlertManager causes the same error:
(MissingPluginException(No implementation found for method sendSms on channel plugins.shounakmulay.com/foreground_sms_channel))
E.g:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final int helloAlarmID = 0;
await AndroidAlarmManager.initialize();
runApp(App());
await AndroidAlarmManager.periodic(
const Duration(minutes: 1),
helloAlarmID,
sendSms,
wakeup: true,
);
}
Future<void> sendSms() async {
try {
Telephony.instance.sendSms(
to: myPhone,
message: myMessage;
} catch (e) {
print(e);
}
}
from telephony.
Any updates!? I am also having the same problem when I try to send a SMS in the background by an android service
from telephony.
I also have the same problem, is there a solution?
from telephony.
I think the problem is that when the app is in background, the plugin initialization does not happen correctly on the android side.
Also if you app is still active in background, call the plugin from the background makes it loose the reference to the original method channel that is used as a communication bridge.
Maybe adding a backgroundInstance
to call telephony methods from the background could be the solution. This way we don't make the original instance inactive and you can still continue using it once the app comes back to the foreground.
from telephony.
This is fixed in v0.1.1.
Checkout https://github.com/shounakmulay/Telephony/tree/v0.1.1#executing-in-background
from telephony.
@shounakmulay For me it doesn't work with firebase background handler. But works when receiving sms in background.
This one works
telephony.listenIncomingSms(
onNewMessage: (SmsMessage message) { ... },
onBackgroundMessage: backgroundMessageHandler,
);
backgroundMessageHandler(SmsMessage message) async {
Telephony.backgroundInstance.sendSms(to: "123456789", message: "Message from background");
}
This one throws Unhandled Exception: MissingPluginException(No implementation found for method sendSms on channel plugins.shounakmulay.com/foreground_sms_channel)
// foreground
FirebaseMessaging.onMessage.listen((RemoteMessage notification) async {
...
Telephony.instance.sendSms(to: phone, message: msg);
});
// background
FirebaseMessaging.onBackgroundMessage(onBackgroundMessage);
Future<void> _onBackgroundMessage(RemoteMessage message) async {
final String phone = message.data['phone'];
final String body = message.data['body'];
Telephony.backgroundInstance.sendSms(to: phone, message: body);
}
Could you please direct what is missing here. There are some other issues maybe related to this about mixing plugins.
How to make Flutter Workmanager plugin and Location plugin work together
from telephony.
@kakajansh will take a look.
Would be great if you could give me some more info like does this happen only with the firebase messaging plugin or does it happen with other plugins as well?
Thanks.
from telephony.
Closing this for now. Feel free to reopen with any updates.
from telephony.
i have an error about using backgroundMessageHandler
Telephony.backgroundInstance.dialPhoneNumber('12345');
Telephony.instance.dialPhoneNumber('1234');
not works,but when used foreground is working fine.
what is the error,please any can helpe to fix this error.
from telephony.
Related Issues (20)
- Lost spaces and newlines in the middle of long SMS
- Fail to send SMS (SmsManager problem) HOT 4
- [BUG] IncomingSmsReceiver listening even when instance is not created leading to crashing of app when a background notification recieves HOT 1
- Not listed SIM 2 sms in list
- Help request HOT 2
- How to navigate to a screen/page from the onBackgroundMessage(SmsMessage message) method
- feedback about foreground background instance HOT 1
- how to fill it in OTPField ? can you create example
- How to get the SMS sent by the user??
- backgrounMessageHandler or backgroundMessageHandler?
- Google messaging App is a problem for capturing SMS by Telephony HOT 1
- Keeps crashing in background HOT 4
- how to stop listening after collecting my sms
- No implementation requestPhoneAndSmsPermissions
- Unhandled Exception: NoSuchMethodError: The getter 'requestPhoneAndSmsPermissions' was called on null. HOT 1
- Unwanted logs in console. HOT 3
- is there a way that i can get the imsi code ?
- Message sending issue
- iOS support for `Sending` SMS
- cant catch sms bug when app closed (background)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from telephony.