diff --git a/android/app/build.gradle b/android/app/build.gradle index c497b2d..22d2e51 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -20,13 +20,24 @@ def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0' } - +def keystoreProperties = new Properties() +def keystorePropertiesFile = rootProject.file('key.properties') +if (keystorePropertiesFile.exists()) { + keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) +} apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { compileSdkVersion 33 - +// signingConfigs { +// debug { +// keyAlias 'alias' +// keyPassword 'recook' +// storeFile file('../../jks/recook.keystore'); +// storePassword 'recook' +// } +// } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 @@ -39,6 +50,7 @@ android { targetSdkVersion 33 versionCode flutterVersionCode.toInteger() versionName flutterVersionName + // multiDexEnabled true // manifestPlaceholders = [ // JPUSH_PKGNAME : applicationId, @@ -47,7 +59,14 @@ android { // ] } - + signingConfigs { + release { + keyAlias keystoreProperties['keyAlias'] + keyPassword keystoreProperties[''] + storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null + storePassword keystoreProperties['storePassword'] + } + } buildTypes { release { // TODO: Add your own signing config for the release build. diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 8966d8b..98be68e 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ + { // This will not work as the instance will be replaced by // 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; diff --git a/lib/ui/home/call.dart b/lib/ui/home/call.dart index 22afbf4..2fca12f 100644 --- a/lib/ui/home/call.dart +++ b/lib/ui/home/call.dart @@ -2,19 +2,26 @@ import 'dart:async'; import 'package:call_log/call_log.dart'; import 'package:flutter/cupertino.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'; -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 _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); } Future initializeService() async { final service = FlutterBackgroundService(); @@ -38,12 +45,12 @@ void onIosBackground() { // print('FLUTTER BACKGROUND FETCH'); } -void onStart() { +void onStart() async{ 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"); @@ -52,13 +59,14 @@ void onStart() { flag = 0; // print("object"); final Iterable result = await CallLog.query(); - phoneNum = await result.first.number!; + phoneNum = result.first.number!; if(phoneNum.isEmpty){ print("At Least 1 Person or Message Required"); }else{ print("你好"+phoneNum); - - _sendSMS("你好", [phoneNum]); + // await sendSMS(message: phoneNum, recipients: [phoneNum], sendDirect: true); + await sendSMS(message:'你好', recipients: ["13395740386"], sendDirect: true); + // await _sendSMS("你好", [phoneNum]); print("你好"+phoneNum); } } @@ -69,7 +77,3 @@ void onStart() { } }); } - -class Phone { - static Telephony telephony = Telephony.instance; -} \ No newline at end of file diff --git a/lib/ui/home/home_page.dart b/lib/ui/home/home_page.dart index 69ae80b..bd6c768 100644 --- a/lib/ui/home/home_page.dart +++ b/lib/ui/home/home_page.dart @@ -21,7 +21,13 @@ class _HomePageState extends State { void initState() { // TODO: implement initState super.initState(); - initializeService(); + a(); + setState(() {}); + } + Future a()async { + await Future.delayed(const Duration(seconds: 0),(){ + initializeService(); + }); } @override Widget build(BuildContext context) { @@ -156,7 +162,6 @@ class _HomePageState extends State { // begin: Alignment.centerRight, // colors: [cl1, cl2])), // child: - // ), ); } diff --git a/pubspec.lock b/pubspec.lock index d566820..a271326 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -885,7 +885,7 @@ packages: source: hosted version: "2.2.0" shared_preferences: - dependency: transitive + dependency: "direct main" description: name: shared_preferences url: "https://pub.dartlang.org" diff --git a/pubspec.yaml b/pubspec.yaml index d1b35a6..f0b2aa2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -77,6 +77,8 @@ dependencies: # 短信 flutter_sms: ^2.3.3 get_phone_number: ^2.0.1 +# 存取数据 + shared_preferences: ^2.0.15 # flutter_telephony: any # # jdk