号码判断发送

master
王亚玲 2 years ago
parent f75a5270fb
commit c41eeea38f

@ -47,12 +47,6 @@ void onStart(ServiceInstance service) async {
service.on('stopService').listen((event) {
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 {
final SharedPreferences prefs = await SharedPreferences.getInstance();
CallState state = await Telephony.instance.callState;
@ -67,42 +61,132 @@ void onStart(ServiceInstance service) async {
bool? idleSw = prefs.getBool('idleSwitch');
int? numberSet = prefs.getInt("numIndex");
List<String>? numberList = prefs.getStringList("addressList");
print("号码设置$numberSet 通讯列表$numberList");
List<String>? noNumberList = prefs.getStringList("specified");
print("号码设置$numberSet 通讯列表$numberList 指定不发送$noNumberList");
if (callState == "IDLE") {
if (flag != 0) {
final Iterable<CallLogEntry> entry = await CallLog.query();
phoneNum = entry.first.number;
callRecords = entry.first.duration;
print(phoneNum);
switch (numberSet) {
case 0:
if (!(noNumberList?.contains(phoneNum))!) {
if (flag > 0) {
print("来电拒接/未接");
print("${phoneNum!}:${ref!}");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref);
Telephony.backgroundInstance
.sendSms(to: phoneNum!, message: ref);
print("发送成功");
} else if (flag == -1) {
print("来电接听");
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;
case 1:
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);
Telephony.backgroundInstance
.sendSms(to: phoneNum!, message: call);
}
print("去电接听");
} else {
if (idleSw!) {
print(idleSw);
print("${phoneNum!}:${idle!}");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: idle);
Telephony.backgroundInstance
.sendSms(to: phoneNum!, message: idle);
}
print("去电未接");
}
print("发送成功");
}
flag = 0;
}else{
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("${phoneNum!}:${idle!}");
Telephony.backgroundInstance
.sendSms(to: phoneNum!, message: idle);
}
print("去电未接");
}
print("发送成功");
}
flag = 0;
}else{
print("123412434124132312232341241242321312312323123323");
}
break;
}
}
} else if (callState == "RINGING") {
//

@ -97,7 +97,8 @@ class _CallRecordsListState extends State<CallRecordsList> {
} else {
print(phoneNum3);
var res = await ExcludeFunc.getContactsList(phoneNum3);
print(res);
if(res) Get.back();
}
// _easyRefreshController.callRefresh();
// phoneNum3.clear();

@ -1,13 +1,13 @@
import 'package:call_log/call_log.dart';
import 'package:flutter/material.dart';
import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:project_telephony/ui/home/set/func/exclude_contacts_func.dart';
import 'package:project_telephony/ui/home/set/specify_phone_page.dart';
import 'package:project_telephony/utils/headers.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_contacts/flutter_contacts.dart';
import '../../../base/base_style.dart';
import '../../../model/phone_num_model.dart';
import '../../widget/plone_back_button.dart';
// class setItem{
@ -15,7 +15,6 @@ import '../../widget/plone_back_button.dart';
// }
class PhoneSetPage extends StatefulWidget {
const PhoneSetPage({Key? key}) : super(key: key);
@override
@ -27,9 +26,7 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
List<Contact>? contact;
List<String> numbers = [];
List<String>? numList = [];
List<String> numList2=[];
List<String>? numList3=[];
final EasyRefreshController _refreshController = EasyRefreshController();
List setList = [
{
"icon": Assets.icons.rylyphone.path,
@ -50,11 +47,12 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
// "select": false,
},
];
@override
void initState() {
_viewLoading();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
@ -71,7 +69,19 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
leading: const CloudBackButton(isSpecial: true),
backgroundColor: kForeGroundColor),
backgroundColor: kForeGroundColor,
body: Column(
body: EasyRefresh(
firstRefresh: true,
controller: _refreshController,
header: MaterialHeader(),
// footer: MaterialFooter(),
onRefresh: () async {
final SharedPreferences prefs =
await SharedPreferences.getInstance();
select = (prefs.getInt("numIndex"))!;
_viewLoading();
setState(() {});
},
child: ListView(
children: [
_getList(),
24.hb,
@ -80,7 +90,8 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
Get.to(() => const SpecifyPhonePage());
},
child: Container(
padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 30.w),
padding:
EdgeInsets.symmetric(horizontal: 32.w, vertical: 30.w),
height: 144.w,
child: ListTile(
leading: SizedBox(
@ -93,8 +104,8 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
),
title: Text(
"指定号码不发送",
style:
TextStyle(fontSize: 32.sp, fontWeight: FontWeight.bold),
style: TextStyle(
fontSize: 32.sp, fontWeight: FontWeight.bold),
),
subtitle: Text(
"通过添加指定号码来设置不发送",
@ -110,6 +121,15 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
)
],
),
)
// Column(
// children: [
//
//
//
// ],
// ),
);
}
@ -125,8 +145,8 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
),
);
}
Future _viewLoading() async {
Future _viewLoading() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
contact = await FlutterContacts.getContacts();
for (var element in contact!) {
@ -134,6 +154,11 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
numbers.add(full!.phones.first.number.replaceAll(" ", ""));
// status.add(false);
}
var numberList = await ExcludeFunc.getContacts();
for (int i = 0; i < numberList.length; i++) {
numList?.add(numberList[i].phone);
}
await prefs.setStringList("specified", numList!);
await prefs.setStringList("addressList", numbers);
// phoneNum.clear();
// final Iterable<CallLogEntry> entries = await CallLog.query();
@ -159,6 +184,7 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
// }
setState(() {});
}
_getListBox(List item, int index) {
final service = FlutterBackgroundService();
return GestureDetector(
@ -166,6 +192,7 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
final SharedPreferences prefs = await SharedPreferences.getInstance();
select = index;
await prefs.setInt("numIndex", index);
print(await service.isRunning());
if (await service.isRunning()) {
service.invoke("stopService");
Future.delayed(const Duration(seconds: 1), () async {
@ -173,10 +200,12 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
});
} else {
service.startService();
Future.delayed(const Duration(seconds: 1), () async {
Future.delayed(const Duration(seconds: 2), () async {
service.invoke("stopService");
});
}
print( prefs.getStringList("specified"));
_refreshController.callRefresh();
// print(_selectIndex);
setState(() {});
},

@ -78,6 +78,7 @@ class _MembersPageState extends State<MembersPage> {
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: EasyRefresh(
firstRefresh: true,
@ -86,7 +87,6 @@ class _MembersPageState extends State<MembersPage> {
controller: _easyRefreshController,
onRefresh: () async {
await UserTool.userProvider.updateUserInfo();
setState(() {});
},
child: Stack(

@ -151,9 +151,7 @@ class PayUtil {
_wxPayStream?.cancel();
}
Future callWxPay({
required WxPayModel payModel,
}) async {
Future callWxPay({required WxPayModel payModel, }) async {
await payWithWeChat(
appId: 'wx3a0b41d12afef4e2',
partnerId: payModel.partnerId,

Loading…
Cancel
Save