王亚玲 2 years ago
commit 58f08ecc1a

@ -5,6 +5,7 @@ import 'package:project_telephony/utils/user_tool.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../constants/api.dart';
import '../model/exclude_phone_model.dart';
import '../model/login_info_model.dart';
import '../model/network/api_client.dart';
import '../model/user_info_model.dart';
@ -54,6 +55,7 @@ class UserProvider extends ChangeNotifier {
await updateUserInfo();
updateConSms();
updateRefSms();
getExclude();
}
Future logout() async {
@ -79,9 +81,11 @@ class UserProvider extends ChangeNotifier {
var base = await apiClient.request(API.app.find, data: {'status': 1});
if (base.code == 0) {
await prefs.remove('conSms');
await prefs.setString('conSms', (UserTool.userProvider.userInfo.tag)==""?"${base
.data['content']}":"${UserTool.userProvider.userInfo.tag}${base
.data['content']}");
await prefs.setString(
'conSms',
(UserTool.userProvider.userInfo.tag) == ""
? "${base.data['content']}"
: "${UserTool.userProvider.userInfo.tag}${base.data['content']}");
service.invoke("stopService");
if (prefs.getBool('kg')!) {
Future.delayed(const Duration(seconds: 1), () async {
@ -91,7 +95,6 @@ class UserProvider extends ChangeNotifier {
} else {
CloudToast.show(base.msg);
}
notifyListeners();
}
@ -101,9 +104,30 @@ class UserProvider extends ChangeNotifier {
var base = await apiClient.request(API.app.find, data: {'status': 2});
if (base.code == 0) {
await prefs.remove('refSms');
await prefs.setString('refSms', (UserTool.userProvider.userInfo.tag)==""?"${base
.data['content']}":"${UserTool.userProvider.userInfo.tag}${base
.data['content']}" );
await prefs.setString(
'refSms',
(UserTool.userProvider.userInfo.tag) == ""
? "${base.data['content']}"
: "${UserTool.userProvider.userInfo.tag}${base.data['content']}");
service.invoke("stopService");
if (prefs.getBool('kg')!) {
Future.delayed(const Duration(seconds: 1), () async {
service.startService();
});
}
} else {
CloudToast.show(base.msg);
}
notifyListeners();
}
Future getExclude() async {
final prefs = await SharedPreferences.getInstance();
final service = FlutterBackgroundService();
var base = await apiClient.request(API.exclude.find);
if (base.code == 0) {
await prefs.remove('exclude');
await prefs.setStringList('exclude', base.data);
service.invoke("stopService");
if (prefs.getBool('kg')!) {
Future.delayed(const Duration(seconds: 1), () async {

@ -1,14 +1,8 @@
import 'dart:async';
import 'dart:ui';
import 'package:call_log/call_log.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:flutter_background_service_android/flutter_background_service_android.dart';
import 'package:flutter_background_service_android/flutter_background_service_android.dart';
import 'package:project_telephony/utils/headers.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:telephony/telephony.dart';
@ -49,10 +43,7 @@ void onStart(ServiceInstance service) async {
int flag = 0;
String? phoneNum = "";
int? callRecords = 0;
String? state1="";
// CallType? state1;
String callState;
final Iterable<CallLogEntry> entry = await CallLog.query();
service.on('stopService').listen((event) {
service.stopSelf();
});
@ -70,11 +61,7 @@ void onStart(ServiceInstance service) async {
print(callState+"$flag");
String? ref = prefs.getString('refSms');
String? con = prefs.getString('conSms');
// print(con);
if (callState == "IDLE") {
//
if (flag != 0) {
final Iterable<CallLogEntry> entry = await CallLog.query();
phoneNum = entry.first.number;
@ -82,11 +69,11 @@ void onStart(ServiceInstance service) async {
print(phoneNum);
if (flag > 0) {
print("来电拒接/未接");
// Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref!);
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref!);
print("发送成功");
} else if(flag==-1){
print("来电接听");
// Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con!);
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con!);
}else {
print(entry.first.callType);
print(entry.first.duration);

Loading…
Cancel
Save