王亚玲 2 years ago
parent 8fd5a9614a
commit 7848c88b0b

@ -1,8 +1,14 @@
<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" tools="http://schemas.android.com/tools">
<!-- Flutter needs it to communicate with the running application <!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc. to allow setting breakpoints, to provide hot reload, etc.
--> -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<!-- <uses-permission android:name="android.permission.INTERNET" />-->
</manifest> </manifest>

@ -1,5 +1,12 @@
<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" tools="http://schemas.android.com/tools" >
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS"/>
<application <application
android:label="短信帮手" android:label="短信帮手"
android:name="${applicationName}" android:name="${applicationName}"

@ -1,7 +1,20 @@
<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" tools="http://schemas.android.com/tools">
<!-- Flutter needs it to communicate with the running application <!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc. to allow setting breakpoints, to provide hot reload, etc.
--> -->
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<!-- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>-->
<!-- <uses-permission android:name="android.permission.READ_PHONE_STATE"/>-->
<!-- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>-->
<!-- <uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>-->
<!-- <uses-permission android:name="android.permission.READ_SMS"/>-->
<!-- <uses-permission android:name="android.permission.READ_PHONE_NUMBERS"/>-->
<!-- <uses-permission android:name="android.permission.INTERNET"/>-->
</manifest> </manifest>

@ -1,22 +1,30 @@
// import 'dart:async'; // 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';
import 'package:flutter/services.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_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_sms/flutter_sms.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:power_logger/power_logger.dart'; import 'package:power_logger/power_logger.dart';
// import 'package:permission_handler/permission_handler.dart';
// import 'package:project_telephony/permission.dart';
// import 'package:project_telephony/ui/login/login_page.dart';
import 'package:project_telephony/ui/tab_navigator.dart';
// import 'package:telephony/telephony.dart'; import 'package:project_telephony/ui/tab_navigator.dart';
import 'package:project_telephony/ui/user/privacy_rights_page.dart';
// onBackgroundMessage(SmsMessage message) { import 'package:telephony/telephony.dart';
// debugPrint("onBackgroundMessage called");
// } void _sendSMS(String message, List<String> 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 { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
@ -24,73 +32,71 @@ 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() { void onIosBackground() {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
// print('FLUTTER BACKGROUND FETCH'); // print('FLUTTER BACKGROUND FETCH');
} }
// void onStart() { void onStart() {
// int flag = 0; int flag = 0;
// String? phoneNum, callState; String? phoneNum, 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");
// if (callState == "IDLE") { if (callState == "IDLE") {
// if (flag != 0) { if (flag != 0) {
// flag = 0; flag = 0;
// final Iterable<CallLogEntry> result = await CallLog.query(); // print("object");
// phoneNum = result.first.number; // final Iterable<CallLogEntry> result = await CallLog.query();
// print(phoneNum); // phoneNum = result.first.number;
// Phone.telephony.sendSms( // // print(phoneNum);
// to: phoneNum!, List<String> recipents = ["13486828191"];
// message: "hello", // CallState state = await telephony.callState;
// isMultipart: true, _sendSMS("你好", recipents);
// ); // phoneNum = result.first.number;
// phoneNum = result.first.number; // // print(phoneNum);
// // print(phoneNum); // Phone.telephony.sendSms(
// Phone.telephony.sendSms( // to: phoneNum!,
// to: phoneNum!, // message: "hello",
// message: "hello", // isMultipart: true,
// isMultipart: true, // );
// ); }
// } } else if (callState == "RINGING") {
// } else if (callState == "RINGING") { flag++;
// flag++; } else if (callState == "OFFHOOK") {
// } else if (callState == "OFFHOOK") { flag++;
// flag++; }
// } });
// }); }
// }
class Phone {
// class Phone { static Telephony telephony = Telephony.instance;
// 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);
@ -101,12 +107,15 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> { class _MyAppState extends State<MyApp> {
String _message = ""; String _message = "";
// This will not work as the instance will be replaced by
// the one in background.
final telephony = Telephony.instance;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
// PowerLogger.start(context, debug: true); // PowerLogger.start(context, debug: true);
final service = FlutterBackgroundService(); final service = FlutterBackgroundService();
final inbox = Telephony.instance.getInboxSms();
// JPush jPush=JPush(); // JPush jPush=JPush();
// jPush.setup( // jPush.setup(
// appKey: "", // appKey: "",
@ -128,7 +137,6 @@ class _MyAppState extends State<MyApp> {
// openAppSettings(); // openAppSettings();
// }); // });
} }
// onMessage(SmsMessage message) async { // onMessage(SmsMessage message) async {
// setState(() { // setState(() {
// _message = message.body ?? "Error reading message body."; // _message = message.body ?? "Error reading message body.";
@ -153,7 +161,7 @@ class _MyAppState extends State<MyApp> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MediaQuery( return MediaQuery(
data: MediaQueryData.fromWindow(WidgetsBinding.instance!.window), data: MediaQueryData.fromWindow(WidgetsBinding.instance.window),
child: ScreenUtilInit( child: ScreenUtilInit(
designSize: const Size(750, 1334), designSize: const Size(750, 1334),
builder: (context, child) { builder: (context, child) {

@ -1,8 +1,9 @@
// import 'dart:async';
// import android.app.PendingIntent; import 'package:call_log/call_log.dart';
// import android.telephony.SmsManager;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_sms/flutter_sms.dart';
import 'package:get_phone_number/get_phone_number.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
import 'package:project_telephony/base/base_style.dart'; import 'package:project_telephony/base/base_style.dart';
import 'package:project_telephony/ui/home/content_details_page.dart'; import 'package:project_telephony/ui/home/content_details_page.dart';
@ -34,6 +35,7 @@ class _ContentPageState extends State<ContentPage> {
// } // }
// } // }
// SmsManager smsManager = SmsManager.getDefault(); // SmsManager smsManager = SmsManager.getDefault();
int _select = 0; int _select = 0;
List<String> textList = ['欢迎你的来电', '祝您生活愉快', '感谢您的来电我们会尽快处理的', '自定义短信内容']; List<String> textList = ['欢迎你的来电', '祝您生活愉快', '感谢您的来电我们会尽快处理的', '自定义短信内容'];
List<String> textList1 = ['自定义短信内容']; List<String> textList1 = ['自定义短信内容'];
@ -92,16 +94,30 @@ class _ContentPageState extends State<ContentPage> {
// }else{ // }else{
// print(content); // print(content);
// } // }
print(content); // print(content);
// sendSms(content); // // sendSms(content);
telephony.sendSms( // telephony.sendSms(
to: "13486828191", // to: "13395740386",
message: content, // message: content,
); // isMultipart: true
// );
List<String> recipents=["13395740386"];
_sendSMS(content,recipents);
// CallState state = await telephony.callState;
// print(state);
// DataState state1 = await telephony.cellularDataState;
// print(state1);
// String? operatorName = await telephony.networkOperatorName;
// print(operatorName);
// NetworkType type = await telephony.dataNetworkType;
// print(type);
// PhoneType type1 = await telephony.phoneType;
// print(type1);
String phoneNumber = await GetPhoneNumber().get();
print('getPhoneNumber result: $phoneNumber');
} }
setState(() {}); setState(() {});
// print("这是数据" + textList[_s lect]); // print("这是数据" + textList[_s lect]);
// print(index); // print(index);
}, },
onLongPress: () { onLongPress: () {
@ -140,4 +156,13 @@ class _ContentPageState extends State<ContentPage> {
), ),
); );
} }
void _sendSMS(String message, List<String> recipients) async {
String _result = await sendSMS(
message: message, recipients: recipients, sendDirect: true)
.catchError((onError) {
print(onError);
});
print(_result);
}
} }

@ -398,6 +398,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "5.5.3+2" version: "5.5.3+2"
flutter_sms:
dependency: "direct main"
description:
name: flutter_sms
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.3"
flutter_test: flutter_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter
@ -429,6 +436,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "4.6.5" version: "4.6.5"
get_phone_number:
dependency: "direct main"
description:
name: get_phone_number
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
glob: glob:
dependency: transitive dependency: transitive
description: description:
@ -1050,6 +1064,62 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.4" version: "2.0.4"
url_launcher:
dependency: transitive
description:
name: url_launcher
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.5"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.17"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.17"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.13"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:
@ -1115,4 +1185,4 @@ packages:
version: "3.1.1" version: "3.1.1"
sdks: sdks:
dart: ">=2.17.0-206.0.dev <3.0.0" dart: ">=2.17.0-206.0.dev <3.0.0"
flutter: ">=2.8.1" flutter: ">=2.10.0"

@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1 version: 1.0.0+1
environment: environment:
sdk: ">=2.15.0 <3.0.0" sdk: ">=2.16.0 <3.0.0"
# Dependencies specify other packages that your package needs in order to work. # Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions # To automatically upgrade your package dependencies to the latest versions
@ -71,6 +71,11 @@ dependencies:
permission_handler_platform_interface: ^3.7.0 permission_handler_platform_interface: ^3.7.0
#日志输出 #日志输出
power_logger: ^1.2.2 power_logger: ^1.2.2
# 短信
flutter_sms: ^2.3.3
get_phone_number: ^2.0.1
# flutter_telephony: any
# # jdk # # jdk
# jverify: ^2.2.5 # jverify: ^2.2.5
## pub 集成 ## pub 集成

Loading…
Cancel
Save