挂断发短信

master
王亚玲 2 years ago
parent 3d04ed9418
commit d66244e002

@ -47,7 +47,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.project_telephony" applicationId "com.example.project_telephony"
minSdkVersion 23 minSdkVersion 23
targetSdkVersion 33 targetSdkVersion 31
versionCode flutterVersionCode.toInteger() versionCode flutterVersionCode.toInteger()
versionName flutterVersionName versionName flutterVersionName

@ -1,5 +1,6 @@
buildscript { buildscript {
ext.kotlin_version = '1.6.10' ext.kotlin_version = '1.6.10'
// ext.kotlin_version = '1.4.10'
repositories { repositories {
// google() // google()
// mavenCentral() // mavenCentral()

@ -11,15 +11,17 @@ import 'package:flutter_sms/flutter_sms.dart';
import 'package:fluwx/fluwx.dart'; import 'package:fluwx/fluwx.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:permission_handler/permission_handler.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:power_logger/power_logger.dart';
import 'package:project_telephony/providers/user_provider.dart'; import 'package:project_telephony/providers/user_provider.dart';
import 'package:project_telephony/ui/home/call.dart'; import 'package:project_telephony/ui/home/call.dart';
import 'package:project_telephony/ui/home/call_sms.dart';
import 'package:project_telephony/ui/tab_navigator.dart'; import 'package:project_telephony/ui/tab_navigator.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:telephony/telephony.dart'; import 'package:telephony/telephony.dart';
import 'package:project_telephony/utils/hive_store.dart'; import 'package:project_telephony/utils/hive_store.dart';
import 'package:workmanager/workmanager.dart';
// void _sendSMS(String message, List<String> recipients) async { // void _sendSMS(String message, List<String> recipients) async {
// try{ // try{
@ -31,95 +33,25 @@ import 'package:project_telephony/utils/hive_store.dart';
// } // }
// } // }
void main() async { void main() async {
// WidgetsFlutterBinding.ensureInitialized();
FlutterError.onError = (details) { FlutterError.onError = (details) {
LoggerData.addData(details); LoggerData.addData(details);
FlutterError.presentError(details); FlutterError.presentError(details);
}; };
// await initializeService(); WidgetsFlutterBinding.ensureInitialized();
await initializeService();
// Workmanager().initialize(
// callbackDispatcher, // The top level function, aka callbackDispatcher
// isInDebugMode: true // If enabled it will post a notification whenever the task is running. Handy for debugging tasks
// );
runApp(const MyApp()); runApp(const MyApp());
} }
// Future<void> 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<CallLogEntry> result = await CallLog.query();
// // print(phoneNum);
// // String message = "This is a test message!";
// // List<String> recipents = ["10000", "10086"];
// // String _result = await sendSMS(message: message, recipients: recipents, sendDirect: true)
// // .catchError((onError) {
// // print(onError);
// // });
// // print(_result);
// phoneNum = result.first.number!;
// // List<String> 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 { class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key); const MyApp({Key? key}) : super(key: key);
@ -129,71 +61,27 @@ class MyApp extends StatefulWidget {
} }
class _MyAppState extends State<MyApp> { class _MyAppState extends State<MyApp> {
// This will not work as the instance will be replaced by
// the one in background.
final telephony = Telephony.instance; final telephony = Telephony.instance;
// final sendSMS=Telephony.instance;
final sendSMS=Telephony.instance;
// FlutterSmsPlatform
@override @override
Future<void> _Getpermission() async{ Future<void> _Getpermission() async{
await [Permission.sms,Permission.phone,].request(); await [Permission.sms,Permission.phone,].request();
} }
@override
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;
// });
_Getpermission(); _Getpermission();
await HiveStore.init(); HiveStore.init();
registerWxApi( registerWxApi(
appId: "wxd930ea5d5a228f5f",universalLink:"https://your.univerallink.com/link/ " appId: "wxd930ea5d5a228f5f",universalLink:"https://your.univerallink.com/link/ "
); );
});
// final inbox = Telephony.instance.getInboxSms();
// JPush jPush=JPush();
// jPush.setup(
// appKey: "",
// channel: "theChannel",
// production: false,
// debug: true
// );
// service.start();
// List<Permission> permissions = [
// Permission.sms,
// Permission.phone,
// ];
// PermissionHelper.check(permissions, onSuccess: () {
// print('onSuccess');
// }, onFailed: () {
// print('onFailed');
// }, onOpenSetting: () {
// print('onOpenSetting');
// openAppSettings();
// });
} }
// onMessage(SmsMessage message) async {
// setState(() {
// _message = message.body ?? "Error reading message body.";
// });
// }
// onSendStatus(SendStatus status) {
// setState(() {
// _message = status == SendStatus.SENT ? "sent" : "delivered";
// });
// }
// Future<void> initPlatformState() async {
// final bool? result = await Phone.telephony.requestPhoneAndSmsPermissions;
// if (result != null && result) {
// Phone.telephony.listenIncomingSms(
// onNewMessage: onMessage, onBackgroundMessage: onBackgroundMessage);
// }
// if (!mounted) return;
// }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -219,7 +107,7 @@ class _MyAppState extends State<MyApp> {
return MediaQuery( return MediaQuery(
// //
data: MediaQueryData.fromWindow( data: MediaQueryData.fromWindow(
WidgetsBinding.instance!.window) WidgetsBinding.instance.window)
.copyWith(textScaleFactor: 1.0), .copyWith(textScaleFactor: 1.0),
child: BotToastInit().call(context, child), child: BotToastInit().call(context, child),
); );

@ -8,26 +8,27 @@ import 'dart:ui';
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/foundation.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:project_telephony/ui/user/user_page.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:telephony/telephony.dart'; import 'package:telephony/telephony.dart';
import './call_sms.dart';
Future<void> _sendSMS(String message, List<String> recipients) async {
try{
String result =
await sendSMS(message: message, recipients: recipients, sendDirect: true);
print(result);
} catch (error){
print(error.toString());
}
} //
// Future<void> _sendSMS(String message, List<String> recipients) async {
// 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<void> initializeService() async { Future<void> initializeService() async {
SharedPreferences preferences = await SharedPreferences.getInstance(); SharedPreferences preferences = await SharedPreferences.getInstance();
@ -80,14 +81,19 @@ void onStart(ServiceInstance service ) async {
print("At Least 1 Person or Message Required"); print("At Least 1 Person or Message Required");
}else{ }else{
print("你好$phoneNum"); print("你好$phoneNum");
// final inbox = telephony.getInboxSms();
Telephony.backgroundInstance.sendSms(to: phoneNum, message: "啦啦啦啦啦");
// telephony.sendSms(to: phoneNum, message: "感谢来电");
// _sendSMS('',[phoneNum]);
// print("你好123123$phoneNum"); // print("你好123123$phoneNum");
} }
} }
} else if (callState == "RINGING") { } else if (callState == "RINGING") {
flag++; flag++;
print('flag $flag');
} else if (callState == "OFFHOOK") { } else if (callState == "OFFHOOK") {
flag++; flag++;
print('flag $flag');
} }
}); });
} }

@ -1,54 +1,63 @@
import 'dart:async'; //
//
import 'package:call_log/call_log.dart'; // import 'dart:async';
import 'package:flutter_sms/flutter_sms.dart'; //
import 'package:telephony/telephony.dart'; // import 'package:call_log/call_log.dart';
bool _speechEnabled=false; // import 'package:flutter_sms/flutter_sms.dart';
Future<void> _sendSMS(String message, List<String> recipients) async { // import 'package:get/get_utils/get_utils.dart';
// String result = await sendSMS(message: message, recipients: recipients, sendDirect: true) // import 'package:telephony/telephony.dart';
// .catchError((onError) { // import 'package:workmanager/workmanager.dart';
// print(onError); //
// }); // import '../user/user_page.dart';
// Future<void> _sendSMS(String message, List<String> recipients) async {
// // await sendSMS(message: message, recipients: recipients, sendDirect: true);
// try{
// String result =
// await sendSMS(message: message, recipients: recipients, sendDirect: true);
// print(result); // print(result);
try{ // } catch (error){
String result = // print(error.toString());
await sendSMS(message: message, recipients: recipients, sendDirect: true); // }
print(result); //
} catch (error){ // }
print(error.toString()); // void callbackDispatcher() {
} // Workmanager().executeTask((task, inputData) async{
void _initSpeech() async{ // // _sendSMS("感谢来电", ["13486828191"]);
_speechEnabled=await canSendSMS(); // // ${Telephony.backgroundInstance.sendSms(to: "13486828191", message: "message")}
} // print("123412312412312312431231231231231231313123:${ _sendSMS("感谢来电", ["13486828191"])}");
Future sms() async{ // await sendSMS(message: "感谢来电", recipients: ["1348å6828191"], sendDirect: true);
int flag = 0; // // sms();//simpleTask will be emitted here.
String phoneNum=""; // return Future.value(true);
String callState; // });
// WidgetsFlutterBinding.ensureInitialized(); // }
Timer.periodic(const Duration(seconds: 1), (timer) async { // void sms() async{
CallState state = await Telephony.instance.callState; // int flag = 0;
callState = state.name; // String phoneNum="";
// print(callState!+" $flag"); // String callState;
if (callState == "IDLE") { // CallState state = await Telephony.instance.callState;
if (flag != 0) { // callState = state.name;
flag = 0; // // print(callState!+" $flag");
// print("object"); // if (callState == "IDLE") {
final Iterable<CallLogEntry> result = await CallLog.query(); // if (flag != 0) {
phoneNum = result.first.number!; // flag = 0;
if(phoneNum.isEmpty){ // // print("object");
print("At Least 1 Person or Message Required"); // final Iterable<CallLogEntry> result = await CallLog.query();
}else{ // phoneNum = result.first.number!;
print("你好"+phoneNum); // if(phoneNum.isEmpty){
// await sendSMS(message: phoneNum, recipients: [phoneNum], sendDirect: true); // print("At Least 1 Person or Message Required");
// await sendSMS(message:'你好', recipients: ["13395740386"], sendDirect: true); // }else{
await _sendSMS("你好", [phoneNum]); // print("你好$phoneNum");
print("你好"+phoneNum); // // telephony.sendSms(to: phoneNum, message: "1234");
} // _sendSMS('感谢来电',[phoneNum]);
} // // print("你好123123$phoneNum");
} else if (callState == "RINGING") { // }
flag++; // }
} else if (callState == "OFFHOOK") { // } else if (callState == "RINGING") {
flag++; // flag++;
} // print('flag $flag');
}); // } else if (callState == "OFFHOOK") {
}} // flag++;
// print('flag $flag');
// }
//
// }

@ -1,5 +1,6 @@
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_sms/flutter_sms.dart';
import 'package:project_telephony/ui/user/user_page.dart'; import 'package:project_telephony/ui/user/user_page.dart';
import 'package:project_telephony/utils/headers.dart'; import 'package:project_telephony/utils/headers.dart';
@ -73,7 +74,7 @@ class _TabNavigatorState extends State<TabNavigator>
BotToast.showText(text: '再点击一次返回退出'); BotToast.showText(text: '再点击一次返回退出');
return false; return false;
} }
await initializeService( );
// APP // APP
return true; return true;
}, },

@ -100,7 +100,7 @@ class _PrivacyRightsPageState extends State<PrivacyRightsPage> {
}, },
title: Text( title: Text(
'获取设备来电', '获取设备来电',
style: Theme.of(context).textTheme.titleMedium, // style: Theme.of(context).textTheme.titleMedium,
), ),
subtitle: const Text( subtitle: const Text(
"获取设备", "获取设备",

@ -17,6 +17,7 @@ import 'package:project_telephony/utils/headers.dart';
import 'package:project_telephony/utils/permissionutils.dart'; import 'package:project_telephony/utils/permissionutils.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:telephony/telephony.dart'; import 'package:telephony/telephony.dart';
import 'package:workmanager/workmanager.dart';
import '../../constants/api.dart'; import '../../constants/api.dart';
import '../../model/network/api_client.dart'; import '../../model/network/api_client.dart';
@ -278,7 +279,8 @@ class _UserPageState extends State<UserPage> {
vle=value; vle=value;
print(vle); print(vle);
if(vle) { if(vle) {
WidgetsFlutterBinding.ensureInitialized(); Telephony.backgroundInstance.sendSms(to: "13395740386", message: "啦啦啦啦啦");
// Workmanager().registerOneOffTask("task-identifier", "simpleTask");
} }
setState((){}); setState((){});
// await Permission.phone.request(); // await Permission.phone.request();

@ -7,14 +7,14 @@ packages:
name: _fe_analyzer_shared name: _fe_analyzer_shared
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "46.0.0" version: "40.0.0"
analyzer: analyzer:
dependency: transitive dependency: transitive
description: description:
name: analyzer name: analyzer
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "4.6.0" version: "4.1.0"
archive: archive:
dependency: transitive dependency: transitive
description: description:
@ -161,7 +161,7 @@ packages:
name: code_builder name: code_builder
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "4.2.0" version: "4.1.0"
collection: collection:
dependency: transitive dependency: transitive
description: description:
@ -390,7 +390,7 @@ packages:
name: flutter_native_splash name: flutter_native_splash
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.3" version: "1.3.2"
flutter_plugin_android_lifecycle: flutter_plugin_android_lifecycle:
dependency: transitive dependency: transitive
description: description:
@ -470,7 +470,7 @@ packages:
name: grinder name: grinder
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.9.2" version: "0.9.1"
highlight: highlight:
dependency: transitive dependency: transitive
description: description:
@ -743,7 +743,7 @@ packages:
name: path_provider_android name: path_provider_android
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.19" version: "2.0.12"
path_provider_ios: path_provider_ios:
dependency: transitive dependency: transitive
description: description:
@ -820,7 +820,7 @@ packages:
name: petitparser name: petitparser
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "5.0.0" version: "4.4.0"
platform: platform:
dependency: transitive dependency: transitive
description: description:
@ -946,7 +946,7 @@ packages:
name: shelf name: shelf
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.2" version: "1.2.0"
shelf_web_socket: shelf_web_socket:
dependency: transitive dependency: transitive
description: description:
@ -1077,7 +1077,7 @@ packages:
name: typed_data name: typed_data
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.1" version: "1.3.0"
universal_io: universal_io:
dependency: transitive dependency: transitive
description: description:
@ -1133,7 +1133,7 @@ packages:
name: url_launcher_web name: url_launcher_web
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.13" version: "2.0.6"
url_launcher_windows: url_launcher_windows:
dependency: transitive dependency: transitive
description: description:
@ -1182,7 +1182,14 @@ packages:
name: win32 name: win32
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.6.1" version: "2.5.2"
workmanager:
dependency: "direct main"
description:
name: workmanager
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.0"
xdg_directories: xdg_directories:
dependency: transitive dependency: transitive
description: description:
@ -1196,7 +1203,7 @@ packages:
name: xml name: xml
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "5.4.1" version: "5.3.1"
yaml: yaml:
dependency: "direct dev" dependency: "direct dev"
description: description:
@ -1206,4 +1213,4 @@ packages:
version: "3.1.1" version: "3.1.1"
sdks: sdks:
dart: ">=2.17.0 <3.0.0" dart: ">=2.17.0 <3.0.0"
flutter: ">=2.10.0" flutter: ">=2.8.0"

@ -41,6 +41,7 @@ dependencies:
call_log: ^4.0.0 call_log: ^4.0.0
permission_handler: ^10.0.0 permission_handler: ^10.0.0
# 后台设置 # 后台设置
workmanager: ^0.5.0
flutter_background_service: ^2.1.3 flutter_background_service: ^2.1.3
flutter_background_service_android: ^2.0.3 flutter_background_service_android: ^2.0.3
device_info_plus: any device_info_plus: any
@ -80,6 +81,7 @@ dependencies:
get_phone_number: ^2.0.1 get_phone_number: ^2.0.1
# 存取数据 # 存取数据
shared_preferences: ^2.0.15 shared_preferences: ^2.0.15
# flutter_telephony: any # flutter_telephony: any
# # jdk # # jdk

Loading…
Cancel
Save