|
|
@ -1,5 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:bot_toast/bot_toast.dart';
|
|
|
|
import 'package:bot_toast/bot_toast.dart';
|
|
|
|
import 'package:call_log/call_log.dart';
|
|
|
|
import 'package:call_log/call_log.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
@ -9,8 +10,9 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:flutter_sms/flutter_sms.dart';
|
|
|
|
import 'package:flutter_sms/flutter_sms.dart';
|
|
|
|
import 'package:fluwx/fluwx.dart';
|
|
|
|
import 'package:fluwx/fluwx.dart';
|
|
|
|
import 'package:get/get_navigation/src/root/get_material_app.dart';
|
|
|
|
import 'package:get/get_navigation/src/root/get_material_app.dart';
|
|
|
|
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
|
|
|
|
import 'package:permission_handler_platform_interface/permission_handler_platform_interface.dart';
|
|
|
|
import 'package:power_logger/power_logger.dart';
|
|
|
|
import 'package:power_logger/power_logger.dart';
|
|
|
|
import 'package:fluwx/fluwx.dart' as fluwx;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:project_telephony/providers/user_provider.dart';
|
|
|
|
import 'package:project_telephony/providers/user_provider.dart';
|
|
|
|
import 'package:project_telephony/ui/tab_navigator.dart';
|
|
|
|
import 'package:project_telephony/ui/tab_navigator.dart';
|
|
|
@ -18,15 +20,15 @@ import 'package:provider/provider.dart';
|
|
|
|
import 'package:telephony/telephony.dart';
|
|
|
|
import 'package:telephony/telephony.dart';
|
|
|
|
import 'package:project_telephony/utils/hive_store.dart';
|
|
|
|
import 'package:project_telephony/utils/hive_store.dart';
|
|
|
|
|
|
|
|
|
|
|
|
void _sendSMS(String message, List<String> recipients) async {
|
|
|
|
// void _sendSMS(String message, List<String> recipients) async {
|
|
|
|
try{
|
|
|
|
// try{
|
|
|
|
String result =
|
|
|
|
// String result =
|
|
|
|
await sendSMS(message: message, recipients: recipients, sendDirect: true);
|
|
|
|
// await sendSMS(message: message, recipients: recipients, sendDirect: true);
|
|
|
|
print(result);
|
|
|
|
// print(result);
|
|
|
|
} on PlatformException catch(e){
|
|
|
|
// } on PlatformException catch(e){
|
|
|
|
print(e.toString());
|
|
|
|
// print(e.toString());
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
void main() async {
|
|
|
|
void main() async {
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
@ -34,89 +36,89 @@ void main() async {
|
|
|
|
LoggerData.addData(details);
|
|
|
|
LoggerData.addData(details);
|
|
|
|
FlutterError.presentError(details);
|
|
|
|
FlutterError.presentError(details);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
await initializeService();
|
|
|
|
// await initializeService();
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
runApp(const MyApp());
|
|
|
|
runApp(const MyApp());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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() {
|
|
|
|
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
|
|
|
// print('FLUTTER BACKGROUND FETCH');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void onStart() {
|
|
|
|
// void onIosBackground() {
|
|
|
|
int flag = 0;
|
|
|
|
// WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
String phoneNum;
|
|
|
|
// // print('FLUTTER BACKGROUND FETCH');
|
|
|
|
String callState;
|
|
|
|
// }
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
//
|
|
|
|
Timer.periodic(const Duration(seconds: 1), (timer) async {
|
|
|
|
// void onStart() {
|
|
|
|
CallState state = await Telephony.instance.callState;
|
|
|
|
// int flag = 0;
|
|
|
|
callState = state.name;
|
|
|
|
// String phoneNum;
|
|
|
|
// print(callState!+" $flag");
|
|
|
|
// String callState;
|
|
|
|
if (callState == "IDLE") {
|
|
|
|
// WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
if (flag != 0) {
|
|
|
|
// Timer.periodic(const Duration(seconds: 1), (timer) async {
|
|
|
|
flag = 0;
|
|
|
|
// CallState state = await Telephony.instance.callState;
|
|
|
|
// print("object");
|
|
|
|
// callState = state.name;
|
|
|
|
final Iterable<CallLogEntry> result = await CallLog.query();
|
|
|
|
// // print(callState!+" $flag");
|
|
|
|
// print(phoneNum);
|
|
|
|
// if (callState == "IDLE") {
|
|
|
|
// String message = "This is a test message!";
|
|
|
|
// if (flag != 0) {
|
|
|
|
// List<String> recipents = ["10000", "10086"];
|
|
|
|
// flag = 0;
|
|
|
|
// String _result = await sendSMS(message: message, recipients: recipents, sendDirect: true)
|
|
|
|
// // print("object");
|
|
|
|
// .catchError((onError) {
|
|
|
|
// final Iterable<CallLogEntry> result = await CallLog.query();
|
|
|
|
// print(onError);
|
|
|
|
// // print(phoneNum);
|
|
|
|
|
|
|
|
// // String message = "This is a test message!";
|
|
|
|
|
|
|
|
// // List<String> recipents = ["10000", "10086"];
|
|
|
|
|
|
|
|
// // String _result = await sendSMS(message: message, recipients: recipents, sendDirect: true)
|
|
|
|
|
|
|
|
// // .catchError((onError) {
|
|
|
|
|
|
|
|
// // print(onError);
|
|
|
|
|
|
|
|
// // });
|
|
|
|
|
|
|
|
// // print(_result);
|
|
|
|
|
|
|
|
// phoneNum = result.first.number!;
|
|
|
|
|
|
|
|
// // List<String> recipents=[
|
|
|
|
|
|
|
|
// // phoneNum
|
|
|
|
|
|
|
|
// // ];
|
|
|
|
|
|
|
|
// if(phoneNum.isEmpty){
|
|
|
|
|
|
|
|
// print("At Least 1 Person or Message Required");
|
|
|
|
|
|
|
|
// }else{
|
|
|
|
|
|
|
|
// print("你好"+phoneNum);
|
|
|
|
|
|
|
|
// _sendSMS("你好", [phoneNum]);
|
|
|
|
|
|
|
|
// print("你好"+phoneNum);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // final SmsSendStatusListener listener = (SendStatus status) {
|
|
|
|
|
|
|
|
// // print(status);
|
|
|
|
|
|
|
|
// // };
|
|
|
|
|
|
|
|
// // Phone.telephony.sendSms(
|
|
|
|
|
|
|
|
// // to: phoneNum!,
|
|
|
|
|
|
|
|
// // message: "hello",
|
|
|
|
|
|
|
|
// // statusListener: listener,
|
|
|
|
|
|
|
|
// // isMultipart: true,
|
|
|
|
|
|
|
|
// //
|
|
|
|
|
|
|
|
// // );
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else if (callState == "RINGING") {
|
|
|
|
|
|
|
|
// flag++;
|
|
|
|
|
|
|
|
// } else if (callState == "OFFHOOK") {
|
|
|
|
|
|
|
|
// flag++;
|
|
|
|
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// print(_result);
|
|
|
|
// }
|
|
|
|
phoneNum = result.first.number!;
|
|
|
|
|
|
|
|
// List<String> recipents=[
|
|
|
|
|
|
|
|
// phoneNum
|
|
|
|
|
|
|
|
// ];
|
|
|
|
|
|
|
|
if(phoneNum.isEmpty){
|
|
|
|
|
|
|
|
print("At Least 1 Person or Message Required");
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
print("你好"+phoneNum);
|
|
|
|
|
|
|
|
_sendSMS("你好", [phoneNum]);
|
|
|
|
|
|
|
|
print("你好"+phoneNum);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// final SmsSendStatusListener listener = (SendStatus status) {
|
|
|
|
|
|
|
|
// print(status);
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// Phone.telephony.sendSms(
|
|
|
|
|
|
|
|
// to: phoneNum!,
|
|
|
|
|
|
|
|
// message: "hello",
|
|
|
|
|
|
|
|
// statusListener: listener,
|
|
|
|
|
|
|
|
// isMultipart: true,
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// );
|
|
|
|
// class Phone {
|
|
|
|
}
|
|
|
|
// static Telephony telephony = Telephony.instance;
|
|
|
|
} else if (callState == "RINGING") {
|
|
|
|
// }
|
|
|
|
flag++;
|
|
|
|
|
|
|
|
} 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);
|
|
|
@ -131,12 +133,16 @@ class _MyAppState extends State<MyApp> {
|
|
|
|
// the one in background.
|
|
|
|
// the one in background.
|
|
|
|
final telephony = Telephony.instance;
|
|
|
|
final telephony = Telephony.instance;
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
|
|
|
|
Future<void> _Getpermission() async{
|
|
|
|
|
|
|
|
await [Permission.sms,Permission.phone,].request();
|
|
|
|
|
|
|
|
}
|
|
|
|
void initState() {
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
|
|
|
|
final service = FlutterBackgroundService();
|
|
|
|
final service = FlutterBackgroundService();
|
|
|
|
Future.delayed(const Duration(milliseconds: 0), () async {
|
|
|
|
Future.delayed(const Duration(milliseconds: 0), () async {
|
|
|
|
//Hive.initFlutter;
|
|
|
|
//Hive.initFlutter;
|
|
|
|
|
|
|
|
_Getpermission();
|
|
|
|
await HiveStore.init();
|
|
|
|
await HiveStore.init();
|
|
|
|
registerWxApi(
|
|
|
|
registerWxApi(
|
|
|
|
appId: "wxd930ea5d5a228f5f",universalLink:"https://your.univerallink.com/link/ "
|
|
|
|
appId: "wxd930ea5d5a228f5f",universalLink:"https://your.univerallink.com/link/ "
|
|
|
|