parent
af9fb50bd1
commit
e2c46a1452
@ -0,0 +1,26 @@
|
||||
//package com
|
||||
//
|
||||
//import android.os.Bundle
|
||||
//import android.os.PersistableBundle
|
||||
//import android.view.KeyEvent
|
||||
//import android.view.View
|
||||
//import io.flutter.plugin.common.MethodCall
|
||||
//import io.flutter.embedding.android.FlutterActivity
|
||||
//import io.flutter.embedding.engine.FlutterEngine
|
||||
//import io.flutter.plugin.common.MethodChannel
|
||||
//import io.flutter.plugins.GeneratedPluginRegistrant
|
||||
//import androidx.annotation.NonNull;
|
||||
//
|
||||
//class MainActivity: FlutterActivity() {
|
||||
// override fun onCreate(savedInstanceState:Bundle?){
|
||||
// super.onCreate(savedInstanceState)
|
||||
// Notifications.createNotificationChannels(this)
|
||||
// }
|
||||
// override fun configureFlutterEngine(flutterEngine:FlutterEngine){
|
||||
// super.configureFlutterEngine(flutterEngine)
|
||||
// val binaryMessenger =flutterEngine.dartExecutor.binaryMessenger
|
||||
// }
|
||||
//// override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
|
||||
////// GeneratedPluginRegistrant.registerWith(flutterEngine);
|
||||
//// }
|
||||
//}
|
@ -0,0 +1,75 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:call_log/call_log.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_background_service/flutter_background_service.dart';
|
||||
import 'package:flutter_sms/flutter_sms.dart';
|
||||
import 'package:telephony/telephony.dart';
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
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();
|
||||
phoneNum = await result.first.number!;
|
||||
if(phoneNum.isEmpty){
|
||||
print("At Least 1 Person or Message Required");
|
||||
}else{
|
||||
print("你好"+phoneNum);
|
||||
|
||||
_sendSMS("你好", [phoneNum]);
|
||||
print("你好"+phoneNum);
|
||||
}
|
||||
}
|
||||
} else if (callState == "RINGING") {
|
||||
flag++;
|
||||
} else if (callState == "OFFHOOK") {
|
||||
flag++;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class Phone {
|
||||
static Telephony telephony = Telephony.instance;
|
||||
}
|
Loading…
Reference in new issue