From 3d04ed94180dc94e31e34dac3f552313061dcfcc Mon Sep 17 00:00:00 2001
From: wylyl22 <2373073266@qq.com>
Date: Wed, 17 Aug 2022 18:05:28 +0800
Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E9=80=81=E7=9F=AD=E4=BF=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
android/app/src/main/AndroidManifest.xml | 9 +--
lib/main.dart | 10 ++-
lib/providers/user_provider.dart | 2 +
lib/ui/home/call.dart | 94 +++++++++++++----------
lib/ui/home/call_sms.dart | 54 +++++++++++++
lib/ui/home/content_page.dart | 15 ++--
lib/ui/home/home_page.dart | 8 +-
lib/ui/tab_navigator.dart | 2 +
lib/ui/user/privacy_rights_page.dart | 4 +-
lib/ui/user/user_page.dart | 15 +++-
pubspec.lock | 10 +--
pubspec.yaml | 3 +-
key/recook.keystore => recook.keystore | Bin
13 files changed, 153 insertions(+), 73 deletions(-)
create mode 100644 lib/ui/home/call_sms.dart
rename key/recook.keystore => recook.keystore (100%)
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 98be68e..b8b6487 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -1,6 +1,6 @@
-
+
-
-
-
+
+
-
+
diff --git a/lib/main.dart b/lib/main.dart
index dc539f2..055ec51 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -15,6 +15,7 @@ import 'package:permission_handler_platform_interface/permission_handler_platfor
import 'package:power_logger/power_logger.dart';
import 'package:project_telephony/providers/user_provider.dart';
+import 'package:project_telephony/ui/home/call.dart';
import 'package:project_telephony/ui/tab_navigator.dart';
import 'package:provider/provider.dart';
import 'package:telephony/telephony.dart';
@@ -31,13 +32,13 @@ import 'package:project_telephony/utils/hive_store.dart';
// }
void main() async {
- WidgetsFlutterBinding.ensureInitialized();
+ // WidgetsFlutterBinding.ensureInitialized();
FlutterError.onError = (details) {
LoggerData.addData(details);
FlutterError.presentError(details);
};
// await initializeService();
- WidgetsFlutterBinding.ensureInitialized();
+
runApp(const MyApp());
}
@@ -131,7 +132,9 @@ class _MyAppState extends State {
// This will not work as the instance will be replaced by
// the one in background.
final telephony = Telephony.instance;
-
+ // final sendSMS=Telephony.instance;
+ final sendSMS=Telephony.instance;
+ // FlutterSmsPlatform
@override
Future _Getpermission() async{
await [Permission.sms,Permission.phone,].request();
@@ -141,6 +144,7 @@ class _MyAppState extends State {
// final service = FlutterBackgroundService();
Future.delayed(const Duration(milliseconds: 0), () async {
//Hive.initFlutter;
+
_Getpermission();
await HiveStore.init();
registerWxApi(
diff --git a/lib/providers/user_provider.dart b/lib/providers/user_provider.dart
index c171227..1601a47 100644
--- a/lib/providers/user_provider.dart
+++ b/lib/providers/user_provider.dart
@@ -29,6 +29,8 @@ class UserProvider extends ChangeNotifier {
}
}
+
+
Future setToken(String token, {User? user}) async {
apiClient.setToken(token);
await HiveStore.appBox!.put('token', token);
diff --git a/lib/ui/home/call.dart b/lib/ui/home/call.dart
index 2fca12f..0efcba0 100644
--- a/lib/ui/home/call.dart
+++ b/lib/ui/home/call.dart
@@ -1,56 +1,72 @@
+
+
+
+
import 'dart:async';
+import 'dart:io';
+import 'dart:ui';
import 'package:call_log/call_log.dart';
import 'package:flutter/cupertino.dart';
+import 'package:flutter/foundation.dart';
+import 'package:flutter/services.dart';
import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:flutter_sms/flutter_sms.dart';
-import 'package:telephony/telephony.dart';
+import 'package:shared_preferences/shared_preferences.dart';
+import 'package:telephony/telephony.dart';
+import './call_sms.dart';
Future _sendSMS(String message, List recipients) async {
- // String result = await sendSMS(message: message, recipients: recipients, sendDirect: true)
- // .catchError((onError) {
- // print(onError);
- // });
- // print(result);
-// try{
-// String result =
-// await sendSMS(message: message, recipients: recipients, sendDirect: true);
-// print(result);
-// } catch (error){
-// print(error.toString());
-// }
- await sendSMS(message: message, recipients: recipients, sendDirect: true);
+ try{
+ String result =
+ await sendSMS(message: message, recipients: recipients, sendDirect: true);
+print(result);
+ } catch (error){
+ print(error.toString());
+ }
+
}
+
Future initializeService() async {
- final service = FlutterBackgroundService();
- service.setNotificationInfo(title: '短信助手', content: '正在后台运行');
- await service.configure(
- androidConfiguration: AndroidConfiguration(
- onStart: onStart,
- autoStart: true,
- isForegroundMode: true,
- ),
- iosConfiguration: IosConfiguration(
- autoStart: true,
- onForeground: onStart,
- onBackground: onIosBackground,
- ),
- );
-}
+ SharedPreferences preferences = await SharedPreferences.getInstance();
+ final service = FlutterBackgroundService();
-void onIosBackground() {
+ await service.configure(
+ androidConfiguration: AndroidConfiguration(
+ // this will be executed when app is in foreground or background in separated isolate
+ onStart: onStart,
+ // auto start service
+ autoStart: false,
+ isForegroundMode: true,
+ ),
+ iosConfiguration: IosConfiguration(
+ // auto start service
+ autoStart: true,
+ // this will be executed when app is in foreground in separated isolate
+ onForeground: onStart,
+ // you have to enable background fetch capability on xcode project
+ onBackground: onIosBackground,
+ ),
+ );
+ service.startService();
+ }
+// }
+
+bool onIosBackground(ServiceInstance service) {
WidgetsFlutterBinding.ensureInitialized();
- // print('FLUTTER BACKGROUND FETCH');
+ print('FLUTTER BACKGROUND FETCH');
+ return true;
}
-void onStart() async{
+
+void onStart(ServiceInstance service ) async {
+ DartPluginRegistrant.ensureInitialized();
int flag = 0;
String phoneNum="";
String callState;
- 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.name;
// print(callState!+" $flag");
@@ -63,11 +79,9 @@ void onStart() async{
if(phoneNum.isEmpty){
print("At Least 1 Person or Message Required");
}else{
- print("你好"+phoneNum);
- // await sendSMS(message: phoneNum, recipients: [phoneNum], sendDirect: true);
- await sendSMS(message:'你好', recipients: ["13395740386"], sendDirect: true);
- // await _sendSMS("你好", [phoneNum]);
- print("你好"+phoneNum);
+ print("你好$phoneNum");
+
+ // print("你好123123$phoneNum");
}
}
} else if (callState == "RINGING") {
@@ -75,5 +89,5 @@ void onStart() async{
} else if (callState == "OFFHOOK") {
flag++;
}
- });
+ });
}
diff --git a/lib/ui/home/call_sms.dart b/lib/ui/home/call_sms.dart
new file mode 100644
index 0000000..4ff99ea
--- /dev/null
+++ b/lib/ui/home/call_sms.dart
@@ -0,0 +1,54 @@
+import 'dart:async';
+
+import 'package:call_log/call_log.dart';
+import 'package:flutter_sms/flutter_sms.dart';
+import 'package:telephony/telephony.dart';
+bool _speechEnabled=false;
+Future _sendSMS(String message, List recipients) async {
+ // String result = await sendSMS(message: message, recipients: recipients, sendDirect: true)
+ // .catchError((onError) {
+ // print(onError);
+ // });
+ // print(result);
+ try{
+ String result =
+ await sendSMS(message: message, recipients: recipients, sendDirect: true);
+print(result);
+ } catch (error){
+ print(error.toString());
+ }
+ void _initSpeech() async{
+ _speechEnabled=await canSendSMS();
+ }
+Future sms() async{
+ int flag = 0;
+ String phoneNum="";
+ String callState;
+ // WidgetsFlutterBinding.ensureInitialized();
+ Timer.periodic(const Duration(seconds: 1), (timer) async {
+ CallState state = await Telephony.instance.callState;
+ callState = state.name;
+ // print(callState!+" $flag");
+ if (callState == "IDLE") {
+ if (flag != 0) {
+ flag = 0;
+ // print("object");
+ final Iterable result = await CallLog.query();
+ phoneNum = result.first.number!;
+ if(phoneNum.isEmpty){
+ print("At Least 1 Person or Message Required");
+ }else{
+ print("你好"+phoneNum);
+ // await sendSMS(message: phoneNum, recipients: [phoneNum], sendDirect: true);
+ // await sendSMS(message:'你好', recipients: ["13395740386"], sendDirect: true);
+ await _sendSMS("你好", [phoneNum]);
+ print("你好"+phoneNum);
+ }
+ }
+ } else if (callState == "RINGING") {
+ flag++;
+ } else if (callState == "OFFHOOK") {
+ flag++;
+ }
+ });
+}}
\ No newline at end of file
diff --git a/lib/ui/home/content_page.dart b/lib/ui/home/content_page.dart
index 4e58334..4db4090 100644
--- a/lib/ui/home/content_page.dart
+++ b/lib/ui/home/content_page.dart
@@ -1,22 +1,16 @@
-import 'dart:async';
-import 'dart:io';
+
import 'package:call_log/call_log.dart';
import 'package:flutter/material.dart';
-import 'package:flutter/services.dart';
-import 'package:flutter_background_service/flutter_background_service.dart';
+
import 'package:flutter_sms/flutter_sms.dart';
-import 'package:get_phone_number/get_phone_number.dart';
-import 'package:hive/hive.dart';
-import 'package:permission_handler/permission_handler.dart';
+
import 'package:project_telephony/base/base_style.dart';
import 'package:project_telephony/ui/home/content_details_page.dart';
import 'package:project_telephony/ui/widget/centertipsalterwidget.dart';
import 'package:project_telephony/ui/widget/plone_back_button.dart';
import 'package:project_telephony/utils/headers.dart';
-import 'package:telephony/telephony.dart';
-import '../user/privacy_rights_page.dart';
class ContentPage extends StatefulWidget {
final bool? isAnswer; //true接听false未接听
@@ -77,6 +71,9 @@ class _ContentPageState extends State {
},
));
} else {
+ final Iterable result = await CallLog.query();
+ phoneNum = result.first.number!;
+ await sendSMS(message:content, recipients: [phoneNum], sendDirect: true);
// bool? permissionsGranted = await telephony.requestPhonePermissions;
// print(permissionsGranted);
// if(permissionsGranted!){
diff --git a/lib/ui/home/home_page.dart b/lib/ui/home/home_page.dart
index bd6c768..a465df9 100644
--- a/lib/ui/home/home_page.dart
+++ b/lib/ui/home/home_page.dart
@@ -21,14 +21,10 @@ class _HomePageState extends State {
void initState() {
// TODO: implement initState
super.initState();
- a();
+ // initializeService();
setState(() {});
}
- Future a()async {
- await Future.delayed(const Duration(seconds: 0),(){
- initializeService();
- });
- }
+
@override
Widget build(BuildContext context) {
return Scaffold(
diff --git a/lib/ui/tab_navigator.dart b/lib/ui/tab_navigator.dart
index 5393997..af50f02 100644
--- a/lib/ui/tab_navigator.dart
+++ b/lib/ui/tab_navigator.dart
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:project_telephony/ui/user/user_page.dart';
import 'package:project_telephony/utils/headers.dart';
+import 'home/call.dart';
import 'home/home_page.dart';
class TabNavigator extends StatefulWidget {
@@ -72,6 +73,7 @@ class _TabNavigatorState extends State
BotToast.showText(text: '再点击一次返回退出');
return false;
}
+ await initializeService( );
// 否则关闭APP
return true;
},
diff --git a/lib/ui/user/privacy_rights_page.dart b/lib/ui/user/privacy_rights_page.dart
index 01995fb..bdbb813 100644
--- a/lib/ui/user/privacy_rights_page.dart
+++ b/lib/ui/user/privacy_rights_page.dart
@@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
-import 'package:permission_handler_platform_interface/permission_handler_platform_interface.dart';
+
import 'package:project_telephony/base/base_style.dart';
import 'package:project_telephony/ui/widget/plone_back_button.dart';
import 'package:project_telephony/utils/headers.dart';
-import 'package:telephony/telephony.dart';
+
class PrivacyRightsPage extends StatefulWidget {
final String name;
diff --git a/lib/ui/user/user_page.dart b/lib/ui/user/user_page.dart
index f2c2378..623d30c 100644
--- a/lib/ui/user/user_page.dart
+++ b/lib/ui/user/user_page.dart
@@ -1,3 +1,5 @@
+import 'dart:async';
+
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -22,6 +24,7 @@ import '../../permission.dart';
import '../../providers/user_provider.dart';
import '../../utils/toast/cloud_toast.dart';
import '../../utils/user_tool.dart';
+import '../home/call.dart';
import '../home/content_details_page.dart';
import '../home/home_page.dart';
@@ -35,8 +38,9 @@ class UserPage extends StatefulWidget {
final Telephony telephony = Telephony.instance;
class _UserPageState extends State {
- bool vle =PermissionStatus.denied.isGranted;
+ // bool vle =PermissionStatus.denied.isGranted;
final userProvider = Provider.of(Get.context!, listen: false);
+ bool vle=false;
@override
Widget build(BuildContext context) {
@@ -234,6 +238,7 @@ class _UserPageState extends State {
//内容
_getSwitch(String url, String name, bool pd) {
+ num a=0;
return GestureDetector(
onTap: () async {
pd
@@ -270,7 +275,13 @@ class _UserPageState extends State {
? Switch(
value: vle,
onChanged: (value) async{
- await Permission.phone.request();
+ vle=value;
+ print(vle);
+ if(vle) {
+ WidgetsFlutterBinding.ensureInitialized();
+ }
+ setState((){});
+ // await Permission.phone.request();
// List permissions = [
// Permission.sms,
// Permission.phone,
diff --git a/pubspec.lock b/pubspec.lock
index a271326..95e4435 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -334,28 +334,28 @@ packages:
name: flutter_background_service
url: "https://pub.dartlang.org"
source: hosted
- version: "0.2.8+5"
+ version: "2.1.3"
flutter_background_service_android:
- dependency: transitive
+ dependency: "direct main"
description:
name: flutter_background_service_android
url: "https://pub.dartlang.org"
source: hosted
- version: "0.0.2"
+ version: "2.0.3"
flutter_background_service_ios:
dependency: transitive
description:
name: flutter_background_service_ios
url: "https://pub.dartlang.org"
source: hosted
- version: "0.0.2"
+ version: "2.1.0"
flutter_background_service_platform_interface:
dependency: transitive
description:
name: flutter_background_service_platform_interface
url: "https://pub.dartlang.org"
source: hosted
- version: "0.0.1+3"
+ version: "2.0.0"
flutter_gen_core:
dependency: transitive
description:
diff --git a/pubspec.yaml b/pubspec.yaml
index f0b2aa2..96da9ce 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -41,7 +41,8 @@ dependencies:
call_log: ^4.0.0
permission_handler: ^10.0.0
# 后台设置
- flutter_background_service: ^0.2.6
+ flutter_background_service: ^2.1.3
+ flutter_background_service_android: ^2.0.3
device_info_plus: any
# 屏幕适配
flutter_screenutil: ^5.5.3+2
diff --git a/key/recook.keystore b/recook.keystore
similarity index 100%
rename from key/recook.keystore
rename to recook.keystore