|
|
@ -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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|