|
|
@ -11,82 +11,82 @@ import 'package:project_telephony/permission.dart';
|
|
|
|
import 'package:project_telephony/ui/login/login_page.dart';
|
|
|
|
import 'package:project_telephony/ui/login/login_page.dart';
|
|
|
|
import 'package:project_telephony/ui/tab_navigator.dart';
|
|
|
|
import 'package:project_telephony/ui/tab_navigator.dart';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:telephony/telephony.dart';
|
|
|
|
// import 'package:telephony/telephony.dart';
|
|
|
|
|
|
|
|
|
|
|
|
onBackgroundMessage(SmsMessage message) {
|
|
|
|
// onBackgroundMessage(SmsMessage message) {
|
|
|
|
debugPrint("onBackgroundMessage called");
|
|
|
|
// debugPrint("onBackgroundMessage called");
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
void main() async {
|
|
|
|
void main() async {
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await initializeService();
|
|
|
|
// await initializeService();
|
|
|
|
runApp(const MyApp());
|
|
|
|
runApp(const MyApp());
|
|
|
|
// SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
|
|
|
|
// SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
|
|
|
|
// statusBarColor: Colors.transparent, //状态栏背景色
|
|
|
|
// statusBarColor: Colors.transparent, //状态栏背景色
|
|
|
|
// statusBarIconBrightness: Brightness.dark); //状态栏字体颜色
|
|
|
|
// statusBarIconBrightness: Brightness.dark); //状态栏字体颜色
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> initializeService() async {
|
|
|
|
// Future<void> initializeService() async {
|
|
|
|
final service = FlutterBackgroundService();
|
|
|
|
// final service = FlutterBackgroundService();
|
|
|
|
service.setNotificationInfo(title: '短信助手', content: '正在后台运行');
|
|
|
|
// service.setNotificationInfo(title: '短信助手', content: '正在后台运行');
|
|
|
|
await service.configure(
|
|
|
|
// await service.configure(
|
|
|
|
androidConfiguration: AndroidConfiguration(
|
|
|
|
// androidConfiguration: AndroidConfiguration(
|
|
|
|
onStart: onStart,
|
|
|
|
// onStart: onStart,
|
|
|
|
autoStart: true,
|
|
|
|
// autoStart: true,
|
|
|
|
isForegroundMode: true,
|
|
|
|
// isForegroundMode: true,
|
|
|
|
),
|
|
|
|
// ),
|
|
|
|
iosConfiguration: IosConfiguration(
|
|
|
|
// iosConfiguration: IosConfiguration(
|
|
|
|
autoStart: true,
|
|
|
|
// autoStart: true,
|
|
|
|
onForeground: onStart,
|
|
|
|
// onForeground: onStart,
|
|
|
|
onBackground: onIosBackground,
|
|
|
|
// onBackground: onIosBackground,
|
|
|
|
),
|
|
|
|
// ),
|
|
|
|
);
|
|
|
|
// );
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
void onIosBackground() {
|
|
|
|
void onIosBackground() {
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
// print('FLUTTER BACKGROUND FETCH');
|
|
|
|
// print('FLUTTER BACKGROUND FETCH');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onStart() {
|
|
|
|
// void onStart() {
|
|
|
|
int flag = 0;
|
|
|
|
// int flag = 0;
|
|
|
|
String? phoneNum, callState;
|
|
|
|
// String? phoneNum, callState;
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
// WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
|
|
|
//
|
|
|
|
Timer.periodic(const Duration(seconds: 1), (timer) async {
|
|
|
|
// Timer.periodic(const Duration(seconds: 1), (timer) async {
|
|
|
|
CallState state = await Telephony.instance.callState;
|
|
|
|
// CallState state = await Telephony.instance.callState;
|
|
|
|
callState = state.name;
|
|
|
|
// callState = state.name;
|
|
|
|
// print(callState!+"$flag");
|
|
|
|
// // print(callState!+"$flag");
|
|
|
|
if (callState == "IDLE") {
|
|
|
|
// if (callState == "IDLE") {
|
|
|
|
if (flag != 0) {
|
|
|
|
// if (flag != 0) {
|
|
|
|
flag = 0;
|
|
|
|
// flag = 0;
|
|
|
|
final Iterable<CallLogEntry> result = await CallLog.query();
|
|
|
|
// final Iterable<CallLogEntry> result = await CallLog.query();
|
|
|
|
phoneNum = result.first.number;
|
|
|
|
// phoneNum = result.first.number;
|
|
|
|
print(phoneNum);
|
|
|
|
|
|
|
|
Phone.telephony.sendSms(
|
|
|
|
|
|
|
|
to: phoneNum!,
|
|
|
|
|
|
|
|
message: "hello",
|
|
|
|
|
|
|
|
isMultipart: true,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
phoneNum = result.first.number;
|
|
|
|
|
|
|
|
// print(phoneNum);
|
|
|
|
// print(phoneNum);
|
|
|
|
Phone.telephony.sendSms(
|
|
|
|
// Phone.telephony.sendSms(
|
|
|
|
to: phoneNum!,
|
|
|
|
// to: phoneNum!,
|
|
|
|
message: "hello",
|
|
|
|
// message: "hello",
|
|
|
|
isMultipart: true,
|
|
|
|
// isMultipart: true,
|
|
|
|
);
|
|
|
|
// );
|
|
|
|
}
|
|
|
|
// phoneNum = result.first.number;
|
|
|
|
} else if (callState == "RINGING") {
|
|
|
|
// // print(phoneNum);
|
|
|
|
flag++;
|
|
|
|
// Phone.telephony.sendSms(
|
|
|
|
} else if (callState == "OFFHOOK") {
|
|
|
|
// to: phoneNum!,
|
|
|
|
flag++;
|
|
|
|
// message: "hello",
|
|
|
|
}
|
|
|
|
// isMultipart: true,
|
|
|
|
});
|
|
|
|
// );
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else if (callState == "RINGING") {
|
|
|
|
class Phone {
|
|
|
|
// flag++;
|
|
|
|
static Telephony telephony = Telephony.instance;
|
|
|
|
// } else if (callState == "OFFHOOK") {
|
|
|
|
}
|
|
|
|
// flag++;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// class Phone {
|
|
|
|
|
|
|
|
// static Telephony telephony = Telephony.instance;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
class MyApp extends StatefulWidget {
|
|
|
|
class MyApp extends StatefulWidget {
|
|
|
|
const MyApp({Key? key}) : super(key: key);
|
|
|
|
const MyApp({Key? key}) : super(key: key);
|
|
|
@ -124,26 +124,26 @@ class _MyAppState extends State<MyApp> {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onMessage(SmsMessage message) async {
|
|
|
|
// onMessage(SmsMessage message) async {
|
|
|
|
setState(() {
|
|
|
|
// setState(() {
|
|
|
|
_message = message.body ?? "Error reading message body.";
|
|
|
|
// _message = message.body ?? "Error reading message body.";
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
onSendStatus(SendStatus status) {
|
|
|
|
// onSendStatus(SendStatus status) {
|
|
|
|
setState(() {
|
|
|
|
// setState(() {
|
|
|
|
_message = status == SendStatus.SENT ? "sent" : "delivered";
|
|
|
|
// _message = status == SendStatus.SENT ? "sent" : "delivered";
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> initPlatformState() async {
|
|
|
|
// Future<void> initPlatformState() async {
|
|
|
|
final bool? result = await Phone.telephony.requestPhoneAndSmsPermissions;
|
|
|
|
// final bool? result = await Phone.telephony.requestPhoneAndSmsPermissions;
|
|
|
|
if (result != null && result) {
|
|
|
|
// if (result != null && result) {
|
|
|
|
Phone.telephony.listenIncomingSms(
|
|
|
|
// Phone.telephony.listenIncomingSms(
|
|
|
|
onNewMessage: onMessage, onBackgroundMessage: onBackgroundMessage);
|
|
|
|
// onNewMessage: onMessage, onBackgroundMessage: onBackgroundMessage);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
if (!mounted) return;
|
|
|
|
// if (!mounted) return;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|