diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 882a27b..8966d8b 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -31,9 +31,11 @@ android:name="flutterEmbedding" android:value="2" /> + - + + diff --git a/android/gradle.properties b/android/gradle.properties index 94adc3a..a777f0e 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,3 +1,4 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true +android.jetifier.blacklist=bcprov-jdk15on diff --git a/lib/main.dart b/lib/main.dart index 3de4cd3..d76307e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,6 @@ import 'dart:async'; + import 'package:bot_toast/bot_toast.dart'; import 'package:call_log/call_log.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:fluwx/fluwx.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:fluwx/fluwx.dart' as fluwx; import 'package:project_telephony/providers/user_provider.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:project_telephony/utils/hive_store.dart'; -void _sendSMS(String message, List recipients) async { - try{ - String result = - await sendSMS(message: message, recipients: recipients, sendDirect: true); - print(result); - } on PlatformException catch(e){ - print(e.toString()); - } -} +// void _sendSMS(String message, List recipients) async { +// try{ +// String result = +// await sendSMS(message: message, recipients: recipients, sendDirect: true); +// print(result); +// } on PlatformException catch(e){ +// print(e.toString()); +// } +// } void main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -34,89 +36,89 @@ void main() async { LoggerData.addData(details); FlutterError.presentError(details); }; - await initializeService(); + // await initializeService(); WidgetsFlutterBinding.ensureInitialized(); runApp(const MyApp()); } -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, - ), - ); -} - -void onIosBackground() { - WidgetsFlutterBinding.ensureInitialized(); - // print('FLUTTER BACKGROUND FETCH'); -} - -void onStart() { - 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(); - // print(phoneNum); - // String message = "This is a test message!"; - // List recipents = ["10000", "10086"]; - // String _result = await sendSMS(message: message, recipients: recipents, sendDirect: true) - // .catchError((onError) { - // print(onError); - // }); - // print(_result); - phoneNum = result.first.number!; - // List 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++; - } - }); -} - -class Phone { - static Telephony telephony = Telephony.instance; -} +// 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, +// ), +// ); +// } + +// void onIosBackground() { +// WidgetsFlutterBinding.ensureInitialized(); +// // print('FLUTTER BACKGROUND FETCH'); +// } +// +// void onStart() { +// 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(); +// // print(phoneNum); +// // String message = "This is a test message!"; +// // List recipents = ["10000", "10086"]; +// // String _result = await sendSMS(message: message, recipients: recipents, sendDirect: true) +// // .catchError((onError) { +// // print(onError); +// // }); +// // print(_result); +// phoneNum = result.first.number!; +// // List 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++; +// } +// }); +// } +// +// class Phone { +// static Telephony telephony = Telephony.instance; +// } class MyApp extends StatefulWidget { const MyApp({Key? key}) : super(key: key); @@ -131,12 +133,16 @@ class _MyAppState extends State { // the one in background. final telephony = Telephony.instance; @override + Future _Getpermission() async{ + await [Permission.sms,Permission.phone,].request(); +} void initState() { super.initState(); final service = FlutterBackgroundService(); Future.delayed(const Duration(milliseconds: 0), () async { //Hive.initFlutter; + _Getpermission(); await HiveStore.init(); registerWxApi( appId: "wxd930ea5d5a228f5f",universalLink:"https://your.univerallink.com/link/ " diff --git a/lib/ui/home/content_page.dart b/lib/ui/home/content_page.dart index f002857..4e58334 100644 --- a/lib/ui/home/content_page.dart +++ b/lib/ui/home/content_page.dart @@ -1,7 +1,9 @@ +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'; @@ -24,6 +26,8 @@ class ContentPage extends StatefulWidget { _ContentPageState createState() => _ContentPageState(); } + + class _ContentPageState extends State { int _select = 0; List textList = ['欢迎你的来电', '祝您生活愉快', '感谢您的来电我们会尽快处理的', '自定义短信内容']; diff --git a/lib/ui/home/home_page.dart b/lib/ui/home/home_page.dart index 6e8945d..6999823 100644 --- a/lib/ui/home/home_page.dart +++ b/lib/ui/home/home_page.dart @@ -1,6 +1,13 @@ +import 'dart:async'; + +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:project_telephony/ui/home/content_page.dart'; import 'package:project_telephony/utils/headers.dart'; +import 'package:telephony/telephony.dart'; class HomePage extends StatefulWidget { const HomePage({Key? key}) : super(key: key); @@ -8,8 +15,104 @@ class HomePage extends StatefulWidget { @override _HomePageState createState() => _HomePageState(); } +void _sendSMS(String message, List recipients) async { + try{ + String result = + await sendSMS(message: message, recipients: recipients, sendDirect: true); + print(result); + } on PlatformException catch(e){ + print(e.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, + ), + ); +} + +void onIosBackground() { + WidgetsFlutterBinding.ensureInitialized(); + // print('FLUTTER BACKGROUND FETCH'); +} + +void onStart() { + 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(); + // print(phoneNum); + // String message = "This is a test message!"; + // List recipents = ["10000", "10086"]; + // String _result = await sendSMS(message: message, recipients: recipents, sendDirect: true) + // .catchError((onError) { + // print(onError); + // }); + // print(_result); + phoneNum = result.first.number!; + // List 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++; + } + }); +} + +class Phone { + static Telephony telephony = Telephony.instance; +} class _HomePageState extends State { + @override + void initState() { + // TODO: implement initState + super.initState(); + Future.delayed(const Duration(milliseconds: 0), () async { + //Hive.initFlutter; + await initializeService(); + + }); + } @override Widget build(BuildContext context) { return Scaffold( diff --git a/lib/ui/user/privacy_rights_page.dart b/lib/ui/user/privacy_rights_page.dart index cceb690..99f9dd8 100644 --- a/lib/ui/user/privacy_rights_page.dart +++ b/lib/ui/user/privacy_rights_page.dart @@ -1,4 +1,5 @@ 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'; @@ -22,27 +23,29 @@ final Telephony telephony = Telephony.instance; // initPlatformState(); // } class _PrivacyRightsPageState extends State { - final Permission _permission = Permission.phone; - final PermissionHandlerPlatform _permissionHandler = - PermissionHandlerPlatform.instance; - PermissionStatus _permissionStatus = PermissionStatus.denied; - - Future requestPermission(Permission permission) async { - final status = await _permissionHandler.requestPermissions([permission]); - setState(() { - _permissionStatus = status[permission] ?? PermissionStatus.denied; - }); - } - + // final Permission _permission = ; + // final PermissionHandlerPlatform _permissionHandler = + // PermissionHandlerPlatform.instance; + // PermissionStatus _permissionStatus = Permission.phone.request() as PermissionStatus; + // PermissionStatus _permissionStatus2 = Permission.sms.request() as PermissionStatus; + + // Future requestPermission(Permission permission) async { + // final status = await _permissionHandler.requestPermissions([permission]); + // setState(() { + // _permissionStatus = status[permission] ?? PermissionStatus.denied; + // }); + // } +bool sms=false; +bool plone=false; @override void initState() { super.initState(); _listenForPermissionStatus(); } - void _listenForPermissionStatus() async { - final status = await _permissionHandler.checkPermissionStatus(_permission); - setState(() => _permissionStatus = status); + Future _listenForPermissionStatus() async { + sms=await Permission.sms.request().isGranted; + plone =await Permission.phone.request().isGranted; } @override @@ -61,144 +64,55 @@ class _PrivacyRightsPageState extends State { leading: const CloudBackButton(isSpecial: true), backgroundColor: kForeGroundColor), backgroundColor: Colors.white, - body: widget.name == "隐私政策" ? null : _getRights(true), + body: widget.name == "隐私政策" ? null : _getRights(), ); } - - // onMessage(SmsMessage message) async { - // setState(() { - // body = message.body ?? "error reading message body."; - // print(body); - // }); - // } - // - // onSendStatus(SendStatus status) { - // setState(() { - // body = status == SendStatus.SENT ? "sent" : "delivered"; - // }); - // } - // - // Future initPlatformState() async { - // final bool? result = await telephony.requestPhoneAndSmsPermissions; - // if (result != null && result) { - // telephony.listenIncomingSms( - // onNewMessage: onMessage, - // onBackgroundMessage: onBackgroundMessage, - // listenInBackground: true); + // Color getPermissionColor() { + // if(true){ + // return Colors.red; + // }else{ + // return Colors.green; // } - // if (!mounted) return; // } - _getRights(bool pd) { - return ListView( - children: Permission.values - .where((permission) { - return permission == Permission.phone || - permission == Permission.sms; - }) - .map((permission) => PermissionWidget(permission)) - .toList()); - } -} - -class PermissionWidget extends StatefulWidget { - const PermissionWidget(this._permission); - - final Permission _permission; - - @override - _PermissionState createState() => _PermissionState(_permission); -} - -class _PermissionState extends State { - _PermissionState(this._permission); - - final Permission _permission; - final PermissionHandlerPlatform _permissionHandler = - PermissionHandlerPlatform.instance; - PermissionStatus _permissionStatus = PermissionStatus.denied; - List title = [ - "获取来电权限", - "获取短信权限", - ]; - List sub = [ - "用于监听来电状态", - "用于发送短信", - ]; - - @override - void initState() { - super.initState(); - - _listenForPermissionStatus(); - } - - void _listenForPermissionStatus() async { - final status = await _permissionHandler.checkPermissionStatus(_permission); - setState(() => _permissionStatus = status); - } - - Color getPermissionColor() { - switch (_permissionStatus) { - case PermissionStatus.denied: - return Colors.red; - case PermissionStatus.granted: - return Colors.green; - case PermissionStatus.limited: - return Colors.orange; - default: - return Colors.red; - } - } - String getPermissionStu() { - switch (_permissionStatus) { - case PermissionStatus.denied: - return "未允许"; - case PermissionStatus.granted: - return "已允许"; - default: - return "未允许"; - } - } - - @override - Widget build(BuildContext context) { - return ListTile( + // String getPermissionStu() { + // if (false) { + // return "未允许"; + // } else { + // return "已允许"; + // } + // } + _getRights(){ + return ListTile( + onTap: ()async{ + // await Permission.phone.request(); + // await Permission.sms.request(); + // Map statuses = await [ + // Permission.sms, + // Permission.phone, + // ].request(); + // + // openAppSettings(); + print(await Permission.phone.request().isGranted); + print(await Permission.sms.request().isGranted); + }, title: Text( - _permission.value==8?title[0]:title[1], + '获取设备来电', style: Theme.of(context).textTheme.titleMedium, ), - subtitle: Text( - _permission.value==8?sub[0]:sub[1], + subtitle: const Text( + "获取设备", ), trailing: Wrap( children: [ - Text(getPermissionStu(), - style: TextStyle(color: getPermissionColor())), + Text(sms & plone ?"已允许":"未允许", + style: TextStyle(color: sms & plone ?Colors.green:Colors.red)), const Icon(Icons.arrow_forward_ios), ], ), - onTap: () { - requestPermission(_permission); - }, - ); - } - void checkServiceStatus( - BuildContext context, PermissionWithService permission) async { - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text( - (await _permissionHandler.checkServiceStatus(permission)).toString()), - )); - } + ); +} - Future requestPermission(Permission permission) async { - final status = await _permissionHandler.requestPermissions([permission]); - setState(() { - print(status); - _permissionStatus = status[permission] ?? PermissionStatus.denied; - print(_permissionStatus); - }); - } -} \ No newline at end of file +} diff --git a/lib/ui/user/user_page.dart b/lib/ui/user/user_page.dart index 0042da0..9d85e50 100644 --- a/lib/ui/user/user_page.dart +++ b/lib/ui/user/user_page.dart @@ -22,6 +22,7 @@ import '../../permission.dart'; import '../../providers/user_provider.dart'; import '../../utils/toast/cloud_toast.dart'; import '../../utils/user_tool.dart'; +import '../home/content_details_page.dart'; import '../home/home_page.dart'; class UserPage extends StatefulWidget { @@ -34,7 +35,7 @@ class UserPage extends StatefulWidget { final Telephony telephony = Telephony.instance; class _UserPageState extends State { - bool vle = false; + bool vle =PermissionStatus.denied.isGranted; final userProvider = Provider.of(Get.context!, listen: false); @override @@ -165,6 +166,7 @@ class _UserPageState extends State { _getBotton() { return GestureDetector( onTap: () { + // print(vle); Get.to(() => const MembersPage()); }, child: Container( @@ -236,7 +238,14 @@ class _UserPageState extends State { onTap: () async { pd ? "" - : Get.to(() => PrivacyRightsPage( + : name=="短信标签"?Get.to(()=> ContentDetailsPage( + content: "", + ploneBack: (String textContent) { + // print("这是数据" + textContent); + // textList.setAll(index, {textContent}); + }, + )): + Get.to(() => PrivacyRightsPage( name: name, )); }, @@ -260,22 +269,23 @@ class _UserPageState extends State { trailing: pd ? Switch( value: vle, - onChanged: (value) { - List permissions = [ - Permission.sms, - Permission.phone, - ]; - PermissionHelper.check(permissions, onSuccess: () { - print('onSuccess'); - }, onFailed: () { - print('onFailed'); - }, onOpenSetting: () { - print('onOpenSetting'); - openAppSettings(); - }); - setState(() { - vle = value; - }); + onChanged: (value) async{ + await Permission.phone.request(); + // List permissions = [ + // Permission.sms, + // Permission.phone, + // ]; + // PermissionHelper.check(permissions, onSuccess: () { + // print('onSuccess'); + // }, onFailed: () { + // print('onFailed'); + // }, onOpenSetting: () { + // print('onOpenSetting'); + // openAppSettings(); + // }); + // setState(() { + // vle = value; + // }); }) : const Icon(Icons.keyboard_arrow_right)), ), diff --git a/pubspec.lock b/pubspec.lock index 72fa926..d566820 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,14 +7,14 @@ packages: name: _fe_analyzer_shared url: "https://pub.dartlang.org" source: hosted - version: "44.0.0" + version: "46.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "4.4.0" + version: "4.6.0" archive: dependency: transitive description: @@ -259,7 +259,7 @@ packages: name: device_info_plus_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.3.0+1" + version: "2.6.1" device_info_plus_web: dependency: transitive description: @@ -743,7 +743,7 @@ packages: name: path_provider_android url: "https://pub.dartlang.org" source: hosted - version: "2.0.17" + version: "2.0.19" path_provider_ios: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index aa6d7c1..d1b35a6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -97,6 +97,7 @@ dev_dependencies: #导入包整理 import_sorter: ^4.5.1 hive_generator: ^1.1.0 + #model自动生成 json_serializable: ^6.1.3 build_runner: ^2.0.2