王亚玲 2 years ago
parent 0e0fc1052b
commit 806f2d96e3

@ -20,13 +20,24 @@ def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) { if (flutterVersionName == null) {
flutterVersionName = '1.0' 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 plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android { android {
compileSdkVersion 33 compileSdkVersion 33
// signingConfigs {
// debug {
// keyAlias 'alias'
// keyPassword 'recook'
// storeFile file('../../jks/recook.keystore');
// storePassword 'recook'
// }
// }
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
@ -39,6 +50,7 @@ android {
targetSdkVersion 33 targetSdkVersion 33
versionCode flutterVersionCode.toInteger() versionCode flutterVersionCode.toInteger()
versionName flutterVersionName versionName flutterVersionName
// multiDexEnabled true // multiDexEnabled true
// manifestPlaceholders = [ // manifestPlaceholders = [
// JPUSH_PKGNAME : applicationId, // 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 { buildTypes {
release { release {
// TODO: Add your own signing config for the release build. // TODO: Add your own signing config for the release build.

@ -1,5 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.project_telephony"> package="com.example.project_telephony">
<uses-permission android:name="android.permission.SEND_SMS"/>
<application <application
android:label="短信帮手" android:label="短信帮手"
android:name="${applicationName}" android:name="${applicationName}"

Binary file not shown.

@ -131,13 +131,13 @@ class _MyAppState extends State<MyApp> {
// This will not work as the instance will be replaced by // This will not work as the instance will be replaced by
// the one in background. // the one in background.
final telephony = Telephony.instance; final telephony = Telephony.instance;
@override @override
Future<void> _Getpermission() async{ Future<void> _Getpermission() async{
await [Permission.sms,Permission.phone,].request(); 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;

@ -2,19 +2,26 @@ import 'dart:async';
import 'package:call_log/call_log.dart'; import 'package:call_log/call_log.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:flutter_background_service/flutter_background_service.dart'; import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:flutter_sms/flutter_sms.dart'; import 'package:flutter_sms/flutter_sms.dart';
import 'package:telephony/telephony.dart'; import 'package:telephony/telephony.dart';
void _sendSMS(String message, List<String> recipients) async {
try{
String result = Future<void> _sendSMS(String message, List<String> recipients) async {
await sendSMS(message: message, recipients: recipients, sendDirect: true); // String result = await sendSMS(message: message, recipients: recipients, sendDirect: true)
print(result); // .catchError((onError) {
} on PlatformException catch(e){ // print(onError);
print(e.toString()); // });
} // 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<void> initializeService() async { Future<void> initializeService() async {
final service = FlutterBackgroundService(); final service = FlutterBackgroundService();
@ -38,12 +45,12 @@ void onIosBackground() {
// print('FLUTTER BACKGROUND FETCH'); // print('FLUTTER BACKGROUND FETCH');
} }
void onStart() { void onStart() async{
int flag = 0; int flag = 0;
String phoneNum=""; String phoneNum="";
String callState; String 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");
@ -52,13 +59,14 @@ void onStart() {
flag = 0; flag = 0;
// print("object"); // print("object");
final Iterable<CallLogEntry> result = await CallLog.query(); final Iterable<CallLogEntry> result = await CallLog.query();
phoneNum = await result.first.number!; phoneNum = result.first.number!;
if(phoneNum.isEmpty){ if(phoneNum.isEmpty){
print("At Least 1 Person or Message Required"); print("At Least 1 Person or Message Required");
}else{ }else{
print("你好"+phoneNum); print("你好"+phoneNum);
// await sendSMS(message: phoneNum, recipients: [phoneNum], sendDirect: true);
_sendSMS("你好", [phoneNum]); await sendSMS(message:'你好', recipients: ["13395740386"], sendDirect: true);
// await _sendSMS("你好", [phoneNum]);
print("你好"+phoneNum); print("你好"+phoneNum);
} }
} }
@ -69,7 +77,3 @@ void onStart() {
} }
}); });
} }
class Phone {
static Telephony telephony = Telephony.instance;
}

@ -21,7 +21,13 @@ class _HomePageState extends State<HomePage> {
void initState() { void initState() {
// TODO: implement initState // TODO: implement initState
super.initState(); super.initState();
initializeService(); a();
setState(() {});
}
Future<void> a()async {
await Future.delayed(const Duration(seconds: 0),(){
initializeService();
});
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -156,7 +162,6 @@ class _HomePageState extends State<HomePage> {
// begin: Alignment.centerRight, // begin: Alignment.centerRight,
// colors: [cl1, cl2])), // colors: [cl1, cl2])),
// child: // child:
// ), // ),
); );
} }

@ -885,7 +885,7 @@ packages:
source: hosted source: hosted
version: "2.2.0" version: "2.2.0"
shared_preferences: shared_preferences:
dependency: transitive dependency: "direct main"
description: description:
name: shared_preferences name: shared_preferences
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"

@ -77,6 +77,8 @@ dependencies:
# 短信 # 短信
flutter_sms: ^2.3.3 flutter_sms: ^2.3.3
get_phone_number: ^2.0.1 get_phone_number: ^2.0.1
# 存取数据
shared_preferences: ^2.0.15
# flutter_telephony: any # flutter_telephony: any
# # jdk # # jdk

Loading…
Cancel
Save