|
|
|
@ -1,4 +1,3 @@
|
|
|
|
|
|
|
|
|
|
import 'dart:async';
|
|
|
|
|
import 'dart:ui';
|
|
|
|
|
|
|
|
|
@ -17,8 +16,6 @@ import 'package:telephony/telephony.dart';
|
|
|
|
|
import '../../providers/user_provider.dart';
|
|
|
|
|
import '../../utils/user_tool.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> initializeService() async {
|
|
|
|
|
// SharedPreferences preferences = await SharedPreferences.getInstance();
|
|
|
|
|
final service = FlutterBackgroundService();
|
|
|
|
@ -40,7 +37,7 @@ Future<void> initializeService() async {
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
service.startService();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
bool onIosBackground(ServiceInstance service) {
|
|
|
|
@ -49,13 +46,11 @@ bool onIosBackground(ServiceInstance service) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void onStart(ServiceInstance service) async {
|
|
|
|
|
DartPluginRegistrant.ensureInitialized();
|
|
|
|
|
int flag = 0;
|
|
|
|
|
String? phoneNum="";
|
|
|
|
|
int? callRecords=0;
|
|
|
|
|
String? phoneNum = "";
|
|
|
|
|
int? callRecords = 0;
|
|
|
|
|
String callState;
|
|
|
|
|
service.on('stopService').listen((event) {
|
|
|
|
|
service.stopSelf();
|
|
|
|
@ -65,20 +60,11 @@ void onStart(ServiceInstance service) async {
|
|
|
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
|
CallState state = await Telephony.instance.callState;
|
|
|
|
|
callState = state.name;
|
|
|
|
|
String? ref=prefs.getString('refSms');
|
|
|
|
|
String? con=prefs.getString('conSms');
|
|
|
|
|
print("这是数据$ref");
|
|
|
|
|
|
|
|
|
|
// bool? kg= prefs.getBool("kg");
|
|
|
|
|
// // bool? kg= prefs.getBool("kg");
|
|
|
|
|
// print("这是数据${prefs.getBool("kg")}");
|
|
|
|
|
// print("这是数据$kg");
|
|
|
|
|
// kg = UserTool.userProvider.kg;
|
|
|
|
|
// print("这是数据${prefs.getBool("kg")}");
|
|
|
|
|
// print(callState!+" $flag");
|
|
|
|
|
print(callState+"$flag");
|
|
|
|
|
String? ref = prefs.getString('refSms');
|
|
|
|
|
String? con = prefs.getString('conSms');
|
|
|
|
|
if (callState == "IDLE") {
|
|
|
|
|
if (flag != 0) {
|
|
|
|
|
flag = 0;
|
|
|
|
|
// print("object");
|
|
|
|
|
final Iterable<CallLogEntry> entry = await CallLog.query();
|
|
|
|
|
phoneNum = entry.first.number;
|
|
|
|
@ -88,16 +74,20 @@ void onStart(ServiceInstance service) async {
|
|
|
|
|
// print('DURATION : ${entry.first.duration}');///通话时长
|
|
|
|
|
// if(callRecords!=0){
|
|
|
|
|
// // if(kg!){
|
|
|
|
|
if (flag > 0) {
|
|
|
|
|
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref!);
|
|
|
|
|
} else {
|
|
|
|
|
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con!);
|
|
|
|
|
}
|
|
|
|
|
// // }
|
|
|
|
|
// }else{
|
|
|
|
|
// print("没接通");
|
|
|
|
|
if (callRecords != 0) {
|
|
|
|
|
print("接通了");
|
|
|
|
|
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "接通了");
|
|
|
|
|
} else {
|
|
|
|
|
print("没接通");
|
|
|
|
|
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "接通了");
|
|
|
|
|
// if (callRecords != 0) {
|
|
|
|
|
// print("接通了");
|
|
|
|
|
// Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "接通了");
|
|
|
|
|
// } else {
|
|
|
|
|
// print("没接通");
|
|
|
|
|
// Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "接通了");
|
|
|
|
|
// if(kg!) {
|
|
|
|
|
// Telephony.backgroundInstance.sendSms(to: phoneNum!, message: "没接通");
|
|
|
|
|
// }
|
|
|
|
@ -109,14 +99,14 @@ void onStart(ServiceInstance service) async {
|
|
|
|
|
// _sendSMS('',[phoneNum]);
|
|
|
|
|
// print("你好123123$phoneNum");
|
|
|
|
|
// }
|
|
|
|
|
flag = 0;
|
|
|
|
|
}
|
|
|
|
|
} else if (callState == "RINGING") {
|
|
|
|
|
flag++;
|
|
|
|
|
// print('flag $flag');
|
|
|
|
|
} else if (callState == "OFFHOOK") {
|
|
|
|
|
flag++;
|
|
|
|
|
if (flag > 0) flag *= -1;
|
|
|
|
|
// print('flag $flag');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|