You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.7 KiB

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);
// });
// 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++;
}
});
}}