|
|
@ -47,18 +47,11 @@ void onStart(ServiceInstance service) async {
|
|
|
|
service.on('stopService').listen((event) {
|
|
|
|
service.on('stopService').listen((event) {
|
|
|
|
service.stopSelf();
|
|
|
|
service.stopSelf();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// setForegroundNotificationInfo(title: "你好", content: "再见");
|
|
|
|
|
|
|
|
// AndroidServiceInstance.
|
|
|
|
|
|
|
|
// service.setNotificationInfo("").listen((event){
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// Telephony.backgroundInstance.sendSms(to: "13486828191", message: "123123");
|
|
|
|
|
|
|
|
Timer.periodic(const Duration(seconds: 1), (timer) async {
|
|
|
|
Timer.periodic(const Duration(seconds: 1), (timer) async {
|
|
|
|
|
|
|
|
|
|
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
CallState state = await Telephony.instance.callState;
|
|
|
|
CallState state = await Telephony.instance.callState;
|
|
|
|
callState = state.name;
|
|
|
|
callState = state.name;
|
|
|
|
print("$callState$flag");
|
|
|
|
// print("$callState$flag");
|
|
|
|
// print(entry.first.duration);
|
|
|
|
// print(entry.first.duration);
|
|
|
|
String? ref = prefs.getString('refSms');
|
|
|
|
String? ref = prefs.getString('refSms');
|
|
|
|
String? con = prefs.getString('conSms');
|
|
|
|
String? con = prefs.getString('conSms');
|
|
|
@ -66,51 +59,143 @@ void onStart(ServiceInstance service) async {
|
|
|
|
String? idle = prefs.getString('idleSms');
|
|
|
|
String? idle = prefs.getString('idleSms');
|
|
|
|
bool? callSw = prefs.getBool('callSwitch');
|
|
|
|
bool? callSw = prefs.getBool('callSwitch');
|
|
|
|
bool? idleSw = prefs.getBool('idleSwitch');
|
|
|
|
bool? idleSw = prefs.getBool('idleSwitch');
|
|
|
|
|
|
|
|
int? numberSet = prefs.getInt("numIndex");
|
|
|
|
|
|
|
|
List<String>? numberList = prefs.getStringList("addressList");
|
|
|
|
|
|
|
|
List<String>? noNumberList = prefs.getStringList("specified");
|
|
|
|
|
|
|
|
print("号码设置$numberSet 通讯列表$numberList 指定不发送$noNumberList");
|
|
|
|
if (callState == "IDLE") {
|
|
|
|
if (callState == "IDLE") {
|
|
|
|
if (flag != 0) {
|
|
|
|
if (flag != 0) {
|
|
|
|
final Iterable<CallLogEntry> entry = await CallLog.query();
|
|
|
|
final Iterable<CallLogEntry> entry = await CallLog.query();
|
|
|
|
phoneNum = entry.first.number;
|
|
|
|
phoneNum = entry.first.number;
|
|
|
|
callRecords = entry.first.duration;
|
|
|
|
callRecords = entry.first.duration;
|
|
|
|
print(phoneNum);
|
|
|
|
print(phoneNum);
|
|
|
|
|
|
|
|
switch (numberSet) {
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
if (!(noNumberList?.contains(phoneNum))!) {
|
|
|
|
if (flag > 0) {
|
|
|
|
if (flag > 0) {
|
|
|
|
print("来电拒接/未接");
|
|
|
|
print("来电拒接/未接");
|
|
|
|
print("${phoneNum!}:${ref!}");
|
|
|
|
print("${phoneNum!}:${ref!}");
|
|
|
|
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref);
|
|
|
|
Telephony.backgroundInstance
|
|
|
|
|
|
|
|
.sendSms(to: phoneNum!, message: ref);
|
|
|
|
print("发送成功");
|
|
|
|
print("发送成功");
|
|
|
|
} else if(flag==-1){
|
|
|
|
} else if (flag == -1) {
|
|
|
|
print("来电接听");
|
|
|
|
print("来电接听");
|
|
|
|
print("${phoneNum!}:${con!}");
|
|
|
|
print("${phoneNum!}:${con!}");
|
|
|
|
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con);
|
|
|
|
Telephony.backgroundInstance
|
|
|
|
|
|
|
|
.sendSms(to: phoneNum!, message: con);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (entry.first.duration! > 0) {
|
|
|
|
|
|
|
|
if (callSw!) {
|
|
|
|
|
|
|
|
print(callSw);
|
|
|
|
|
|
|
|
print("${phoneNum!}:${call!}");
|
|
|
|
|
|
|
|
Telephony.backgroundInstance
|
|
|
|
|
|
|
|
.sendSms(to: phoneNum!, message: call);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
print("去电接听");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (idleSw!) {
|
|
|
|
|
|
|
|
print(idleSw);
|
|
|
|
|
|
|
|
print("${phoneNum!}:${idle!}");
|
|
|
|
|
|
|
|
Telephony.backgroundInstance
|
|
|
|
|
|
|
|
.sendSms(to: phoneNum!, message: idle);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
print("去电未接");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
print("发送成功");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
flag = 0;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
print("123412434124132312232341241242321312312323123323");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
if(entry.first.duration!>0){
|
|
|
|
case 1:
|
|
|
|
if(callSw!){
|
|
|
|
if ((numberList?.contains(phoneNum))! ||
|
|
|
|
|
|
|
|
!(noNumberList?.contains(phoneNum))!) {
|
|
|
|
|
|
|
|
if (flag > 0) {
|
|
|
|
|
|
|
|
print("来电拒接/未接");
|
|
|
|
|
|
|
|
print("${phoneNum!}:${ref!}");
|
|
|
|
|
|
|
|
Telephony.backgroundInstance
|
|
|
|
|
|
|
|
.sendSms(to: phoneNum!, message: ref);
|
|
|
|
|
|
|
|
print("发送成功");
|
|
|
|
|
|
|
|
} else if (flag == -1) {
|
|
|
|
|
|
|
|
print("来电接听");
|
|
|
|
|
|
|
|
print("${phoneNum!}:${con!}");
|
|
|
|
|
|
|
|
Telephony.backgroundInstance
|
|
|
|
|
|
|
|
.sendSms(to: phoneNum!, message: con);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (entry.first.duration! > 0) {
|
|
|
|
|
|
|
|
if (callSw!) {
|
|
|
|
print(callSw);
|
|
|
|
print(callSw);
|
|
|
|
print("${phoneNum!}:${call!}");
|
|
|
|
print("${phoneNum!}:${call!}");
|
|
|
|
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: call);
|
|
|
|
Telephony.backgroundInstance
|
|
|
|
|
|
|
|
.sendSms(to: phoneNum!, message: call);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print("去电接听");
|
|
|
|
print("去电接听");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (idleSw!) {
|
|
|
|
|
|
|
|
print(idleSw);
|
|
|
|
|
|
|
|
print("${phoneNum!}:${idle!}");
|
|
|
|
|
|
|
|
Telephony.backgroundInstance
|
|
|
|
|
|
|
|
.sendSms(to: phoneNum!, message: idle);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
print("去电未接");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
print("发送成功");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
flag = 0;
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
if(idleSw!){
|
|
|
|
print("123412434124132312232341241242321312312323123323");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
if (!(numberList?.contains(phoneNum))! ||
|
|
|
|
|
|
|
|
!(noNumberList?.contains(phoneNum))!) {
|
|
|
|
|
|
|
|
if (flag > 0) {
|
|
|
|
|
|
|
|
print("来电拒接/未接");
|
|
|
|
|
|
|
|
print("${phoneNum!}:${ref!}");
|
|
|
|
|
|
|
|
Telephony.backgroundInstance
|
|
|
|
|
|
|
|
.sendSms(to: phoneNum!, message: ref);
|
|
|
|
|
|
|
|
print("发送成功");
|
|
|
|
|
|
|
|
} else if (flag == -1) {
|
|
|
|
|
|
|
|
print("来电接听");
|
|
|
|
|
|
|
|
print("${phoneNum!}:${con!}");
|
|
|
|
|
|
|
|
Telephony.backgroundInstance
|
|
|
|
|
|
|
|
.sendSms(to: phoneNum!, message: con);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (entry.first.duration! > 0) {
|
|
|
|
|
|
|
|
if (callSw!) {
|
|
|
|
|
|
|
|
print(callSw);
|
|
|
|
|
|
|
|
print("${phoneNum!}:${call!}");
|
|
|
|
|
|
|
|
Telephony.backgroundInstance
|
|
|
|
|
|
|
|
.sendSms(to: phoneNum!, message: call);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
print("去电接听");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (idleSw!) {
|
|
|
|
print(idleSw);
|
|
|
|
print(idleSw);
|
|
|
|
print("${phoneNum!}:${idle!}");
|
|
|
|
print("${phoneNum!}:${idle!}");
|
|
|
|
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: idle);
|
|
|
|
Telephony.backgroundInstance
|
|
|
|
|
|
|
|
.sendSms(to: phoneNum!, message: idle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print("去电未接");
|
|
|
|
print("去电未接");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print("发送成功");
|
|
|
|
print("发送成功");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
flag = 0;
|
|
|
|
flag = 0;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
print("123412434124132312232341241242321312312323123323");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (callState == "RINGING") {
|
|
|
|
} else if (callState == "RINGING") {
|
|
|
|
//响铃
|
|
|
|
//响铃
|
|
|
|
flag=1;
|
|
|
|
flag = 1;
|
|
|
|
print('通话');
|
|
|
|
print('通话');
|
|
|
|
} else if (callState == "OFFHOOK") {
|
|
|
|
} else if (callState == "OFFHOOK") {
|
|
|
|
//通话
|
|
|
|
//通话
|
|
|
|
if (flag > 0) flag *= -1;
|
|
|
|
if (flag > 0) flag *= -1;
|
|
|
|
if(flag==0)flag=-2;
|
|
|
|
if (flag == 0) flag = -2;
|
|
|
|
print('不通话');
|
|
|
|
print('不通话');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|