parent
3d04ed9418
commit
d66244e002
@ -1,54 +1,63 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:call_log/call_log.dart';
|
||||
import 'package:flutter_sms/flutter_sms.dart';
|
||||
import 'package:telephony/telephony.dart';
|
||||
bool _speechEnabled=false;
|
||||
Future<void> _sendSMS(String message, List<String> recipients) async {
|
||||
// String result = await sendSMS(message: message, recipients: recipients, sendDirect: true)
|
||||
// .catchError((onError) {
|
||||
// print(onError);
|
||||
// });
|
||||
//
|
||||
//
|
||||
// import 'dart:async';
|
||||
//
|
||||
// import 'package:call_log/call_log.dart';
|
||||
// import 'package:flutter_sms/flutter_sms.dart';
|
||||
// import 'package:get/get_utils/get_utils.dart';
|
||||
// import 'package:telephony/telephony.dart';
|
||||
// import 'package:workmanager/workmanager.dart';
|
||||
//
|
||||
// import '../user/user_page.dart';
|
||||
// Future<void> _sendSMS(String message, List<String> recipients) async {
|
||||
// // await sendSMS(message: message, recipients: recipients, sendDirect: true);
|
||||
// try{
|
||||
// String result =
|
||||
// await sendSMS(message: message, recipients: recipients, sendDirect: true);
|
||||
// print(result);
|
||||
try{
|
||||
String result =
|
||||
await sendSMS(message: message, recipients: recipients, sendDirect: true);
|
||||
print(result);
|
||||
} catch (error){
|
||||
print(error.toString());
|
||||
}
|
||||
void _initSpeech() async{
|
||||
_speechEnabled=await canSendSMS();
|
||||
}
|
||||
Future sms() async{
|
||||
int flag = 0;
|
||||
String phoneNum="";
|
||||
String callState;
|
||||
// WidgetsFlutterBinding.ensureInitialized();
|
||||
Timer.periodic(const Duration(seconds: 1), (timer) async {
|
||||
CallState state = await Telephony.instance.callState;
|
||||
callState = state.name;
|
||||
// print(callState!+" $flag");
|
||||
if (callState == "IDLE") {
|
||||
if (flag != 0) {
|
||||
flag = 0;
|
||||
// print("object");
|
||||
final Iterable<CallLogEntry> result = await CallLog.query();
|
||||
phoneNum = result.first.number!;
|
||||
if(phoneNum.isEmpty){
|
||||
print("At Least 1 Person or Message Required");
|
||||
}else{
|
||||
print("你好"+phoneNum);
|
||||
// await sendSMS(message: phoneNum, recipients: [phoneNum], sendDirect: true);
|
||||
// await sendSMS(message:'你好', recipients: ["13395740386"], sendDirect: true);
|
||||
await _sendSMS("你好", [phoneNum]);
|
||||
print("你好"+phoneNum);
|
||||
}
|
||||
}
|
||||
} else if (callState == "RINGING") {
|
||||
flag++;
|
||||
} else if (callState == "OFFHOOK") {
|
||||
flag++;
|
||||
}
|
||||
});
|
||||
}}
|
||||
// } catch (error){
|
||||
// print(error.toString());
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// void callbackDispatcher() {
|
||||
// Workmanager().executeTask((task, inputData) async{
|
||||
// // _sendSMS("感谢来电", ["13486828191"]);
|
||||
// // ${Telephony.backgroundInstance.sendSms(to: "13486828191", message: "message")}
|
||||
// print("123412312412312312431231231231231231313123:${ _sendSMS("感谢来电", ["13486828191"])}");
|
||||
// await sendSMS(message: "感谢来电", recipients: ["1348å6828191"], sendDirect: true);
|
||||
// // sms();//simpleTask will be emitted here.
|
||||
// return Future.value(true);
|
||||
// });
|
||||
// }
|
||||
// void sms() async{
|
||||
// int flag = 0;
|
||||
// String phoneNum="";
|
||||
// String callState;
|
||||
// CallState state = await Telephony.instance.callState;
|
||||
// callState = state.name;
|
||||
// // print(callState!+" $flag");
|
||||
// if (callState == "IDLE") {
|
||||
// if (flag != 0) {
|
||||
// flag = 0;
|
||||
// // print("object");
|
||||
// final Iterable<CallLogEntry> result = await CallLog.query();
|
||||
// phoneNum = result.first.number!;
|
||||
// if(phoneNum.isEmpty){
|
||||
// print("At Least 1 Person or Message Required");
|
||||
// }else{
|
||||
// print("你好$phoneNum");
|
||||
// // telephony.sendSms(to: phoneNum, message: "1234");
|
||||
// _sendSMS('感谢来电',[phoneNum]);
|
||||
// // print("你好123123$phoneNum");
|
||||
// }
|
||||
// }
|
||||
// } else if (callState == "RINGING") {
|
||||
// flag++;
|
||||
// print('flag $flag');
|
||||
// } else if (callState == "OFFHOOK") {
|
||||
// flag++;
|
||||
// print('flag $flag');
|
||||
// }
|
||||
//
|
||||
// }
|
Loading…
Reference in new issue