挂断发短信

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).
applicationId "com.example.project_telephony"
minSdkVersion 23
targetSdkVersion 33
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName

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

@ -11,15 +11,17 @@ 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:project_telephony/providers/user_provider.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:provider/provider.dart';
import 'package:telephony/telephony.dart';
import 'package:project_telephony/utils/hive_store.dart';
import 'package:workmanager/workmanager.dart';
// void _sendSMS(String message, List<String> recipients) async {
// try{
@ -31,95 +33,25 @@ import 'package:project_telephony/utils/hive_store.dart';
// }
// }
void main() async {
// WidgetsFlutterBinding.ensureInitialized();
FlutterError.onError = (details) {
LoggerData.addData(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());
}
// 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 {
const MyApp({Key? key}) : super(key: key);
@ -129,71 +61,27 @@ class MyApp extends StatefulWidget {
}
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 sendSMS=Telephony.instance;
final sendSMS=Telephony.instance;
// FlutterSmsPlatform
@override
Future<void> _Getpermission() async{
await [Permission.sms,Permission.phone,].request();
}
@override
void initState() {
super.initState();
// final service = FlutterBackgroundService();
Future.delayed(const Duration(milliseconds: 0), () async {
//Hive.initFlutter;
// Future.delayed(const Duration(milliseconds: 0), () async {
// //Hive.initFlutter;
// });
_Getpermission();
await HiveStore.init();
HiveStore.init();
registerWxApi(
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
Widget build(BuildContext context) {
@ -219,7 +107,7 @@ class _MyAppState extends State<MyApp> {
return MediaQuery(
//
data: MediaQueryData.fromWindow(
WidgetsBinding.instance!.window)
WidgetsBinding.instance.window)
.copyWith(textScaleFactor: 1.0),
child: BotToastInit().call(context, child),
);

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

@ -1,54 +1,63 @@
import 'dart:async';
import 'package:call_log/call_log.dart';
import 'package:flutter_sms/flutter_sms.dart';
import 'package:telephony/telephony.dart';
bool _speechEnabled=false;
Future<void> _sendSMS(String message, List<String> 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());
}
void _initSpeech() async{
_speechEnabled=await canSendSMS();
}
Future sms() async{
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();
phoneNum = result.first.number!;
if(phoneNum.isEmpty){
print("At Least 1 Person or Message Required");
}else{
print("你好"+phoneNum);
// await sendSMS(message: phoneNum, recipients: [phoneNum], sendDirect: true);
// await sendSMS(message:'你好', recipients: ["13395740386"], sendDirect: true);
await _sendSMS("你好", [phoneNum]);
print("你好"+phoneNum);
}
}
} else if (callState == "RINGING") {
flag++;
} else if (callState == "OFFHOOK") {
flag++;
}
});
}}
//
//
// import 'dart:async';
//
// import 'package:call_log/call_log.dart';
// import 'package:flutter_sms/flutter_sms.dart';
// import 'package:get/get_utils/get_utils.dart';
// import 'package:telephony/telephony.dart';
// import 'package:workmanager/workmanager.dart';
//
// 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);
// } catch (error){
// print(error.toString());
// }
//
// }
// void callbackDispatcher() {
// Workmanager().executeTask((task, inputData) async{
// // _sendSMS("感谢来电", ["13486828191"]);
// // ${Telephony.backgroundInstance.sendSms(to: "13486828191", message: "message")}
// print("123412312412312312431231231231231231313123:${ _sendSMS("感谢来电", ["13486828191"])}");
// await sendSMS(message: "感谢来电", recipients: ["1348å6828191"], sendDirect: true);
// // sms();//simpleTask will be emitted here.
// return Future.value(true);
// });
// }
// void sms() async{
// int flag = 0;
// String phoneNum="";
// String callState;
// 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();
// phoneNum = result.first.number!;
// if(phoneNum.isEmpty){
// print("At Least 1 Person or Message Required");
// }else{
// print("你好$phoneNum");
// // telephony.sendSms(to: phoneNum, message: "1234");
// _sendSMS('感谢来电',[phoneNum]);
// // print("你好123123$phoneNum");
// }
// }
// } else if (callState == "RINGING") {
// 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:flutter/material.dart';
import 'package:flutter_sms/flutter_sms.dart';
import 'package:project_telephony/ui/user/user_page.dart';
import 'package:project_telephony/utils/headers.dart';
@ -73,7 +74,7 @@ class _TabNavigatorState extends State<TabNavigator>
BotToast.showText(text: '再点击一次返回退出');
return false;
}
await initializeService( );
// APP
return true;
},

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

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

@ -7,14 +7,14 @@ packages:
name: _fe_analyzer_shared
url: "https://pub.dartlang.org"
source: hosted
version: "46.0.0"
version: "40.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "4.6.0"
version: "4.1.0"
archive:
dependency: transitive
description:
@ -161,7 +161,7 @@ packages:
name: code_builder
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.0"
version: "4.1.0"
collection:
dependency: transitive
description:
@ -390,7 +390,7 @@ packages:
name: flutter_native_splash
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.3"
version: "1.3.2"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
@ -470,7 +470,7 @@ packages:
name: grinder
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.2"
version: "0.9.1"
highlight:
dependency: transitive
description:
@ -743,7 +743,7 @@ packages:
name: path_provider_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.19"
version: "2.0.12"
path_provider_ios:
dependency: transitive
description:
@ -820,7 +820,7 @@ packages:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.0"
version: "4.4.0"
platform:
dependency: transitive
description:
@ -946,7 +946,7 @@ packages:
name: shelf
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.2"
version: "1.2.0"
shelf_web_socket:
dependency: transitive
description:
@ -1077,7 +1077,7 @@ packages:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
version: "1.3.0"
universal_io:
dependency: transitive
description:
@ -1133,7 +1133,7 @@ packages:
name: url_launcher_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.13"
version: "2.0.6"
url_launcher_windows:
dependency: transitive
description:
@ -1182,7 +1182,14 @@ packages:
name: win32
url: "https://pub.dartlang.org"
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:
dependency: transitive
description:
@ -1196,7 +1203,7 @@ packages:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "5.4.1"
version: "5.3.1"
yaml:
dependency: "direct dev"
description:
@ -1206,4 +1213,4 @@ packages:
version: "3.1.1"
sdks:
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
permission_handler: ^10.0.0
# 后台设置
workmanager: ^0.5.0
flutter_background_service: ^2.1.3
flutter_background_service_android: ^2.0.3
device_info_plus: any
@ -80,6 +81,7 @@ dependencies:
get_phone_number: ^2.0.1
# 存取数据
shared_preferences: ^2.0.15
# flutter_telephony: any
# # jdk

Loading…
Cancel
Save