dyb
戴余标 2 years ago
parent 862f4f351c
commit ad97721b05

@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android { android {
compileSdkVersion flutter.compileSdkVersion compileSdkVersion 33
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
@ -36,7 +36,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 32 targetSdkVersion 33
versionCode flutterVersionCode.toInteger() versionCode flutterVersionCode.toInteger()
versionName flutterVersionName versionName flutterVersionName
} }

@ -2,6 +2,8 @@ import 'dart:async';
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_background_service/flutter_background_service.dart'; import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:project_telephony/permission.dart';
import 'package:telephony/telephony.dart'; import 'package:telephony/telephony.dart';
onBackgroundMessage(SmsMessage message) { onBackgroundMessage(SmsMessage message) {
@ -16,6 +18,7 @@ Future<void> main() async {
Future<void> initializeService() async { Future<void> initializeService() async {
final service = FlutterBackgroundService(); final service = FlutterBackgroundService();
service.setNotificationInfo(title: '短信助手',content: '正在后台运行');
await service.configure( await service.configure(
androidConfiguration: AndroidConfiguration( androidConfiguration: AndroidConfiguration(
onStart: onStart, onStart: onStart,
@ -48,7 +51,7 @@ void onStart() {
if (flag != 0) { if (flag != 0) {
flag = 0; flag = 0;
final Iterable<CallLogEntry> result = await CallLog.query(); final Iterable<CallLogEntry> result = await CallLog.query();
phoneNum = await result.first.number; phoneNum = result.first.number;
print(phoneNum); print(phoneNum);
Phone.telephony.sendSms(to: phoneNum!, message: "hello",isMultipart:true,); Phone.telephony.sendSms(to: phoneNum!, message: "hello",isMultipart:true,);
} }
@ -79,6 +82,19 @@ class _MyAppState extends State<MyApp> {
super.initState(); super.initState();
final service = FlutterBackgroundService(); final service = FlutterBackgroundService();
service.start(); 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 { onMessage(SmsMessage message) async {

@ -0,0 +1,53 @@
import 'package:flutter/cupertino.dart';
import 'package:permission_handler/permission_handler.dart';
class PermissionHelper {
static VoidCallback defaultCall = () {};
///
static void check(List<Permission> permissionList,
{String? errMsg,
VoidCallback? onSuccess,
VoidCallback? onFailed,
VoidCallback? onOpenSetting}) async {
bool flag = true;
for (var value in permissionList) {
var status = await value.status;
if (!status.isGranted) {
flag = false;
break;
}
}
if (!flag) {
PermissionStatus permissionStatus =
await requestPermission(permissionList);
if (permissionStatus.isGranted) {
onSuccess != null ? onSuccess() : defaultCall();
} else if (permissionStatus.isDenied) {
onFailed != null ? onFailed() : defaultCall();
} else if (permissionStatus.isPermanentlyDenied) {
onOpenSetting != null ? onOpenSetting() : defaultCall();
} else if (permissionStatus.isRestricted) {
//IOS
onOpenSetting != null ? onOpenSetting() : defaultCall();
} else if (permissionStatus.isLimited) {
//IOS
onOpenSetting != null ? onOpenSetting() : defaultCall();
}
}
}
//
static Future<PermissionStatus> requestPermission(
List<Permission> permissionList) async {
Map<Permission, PermissionStatus> statuses = await permissionList.request();
PermissionStatus currentPermissionStatus = PermissionStatus.granted;
statuses.forEach((key, value) {
if (!value.isGranted) {
currentPermissionStatus = value;
return;
}
});
return currentPermissionStatus;
}
}

@ -57,48 +57,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.5" version: "1.0.5"
device_info_plus:
dependency: "direct main"
description:
name: device_info_plus
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
device_info_plus_linux:
dependency: transitive
description:
name: device_info_plus_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
device_info_plus_macos:
dependency: transitive
description:
name: device_info_plus_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.3"
device_info_plus_platform_interface:
dependency: transitive
description:
name: device_info_plus_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.0+1"
device_info_plus_web:
dependency: transitive
description:
name: device_info_plus_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
device_info_plus_windows:
dependency: transitive
description:
name: device_info_plus_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:
@ -106,20 +64,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0" version: "1.2.0"
ffi:
dependency: transitive
description:
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.1"
file:
dependency: transitive
description:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.2"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
@ -144,18 +88,6 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
lints: lints:
dependency: transitive dependency: transitive
description: description:
@ -177,20 +109,48 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.7.0" version: "1.7.0"
nested: path:
dependency: transitive dependency: transitive
description: description:
name: nested name: path
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.0" version: "1.8.0"
path: permission_handler:
dependency: "direct main"
description:
name: permission_handler
url: "https://pub.dartlang.org"
source: hosted
version: "10.0.0"
permission_handler_android:
dependency: transitive dependency: transitive
description: description:
name: path name: permission_handler_android
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.0" version: "10.0.0"
permission_handler_apple:
dependency: transitive
description:
name: permission_handler_apple
url: "https://pub.dartlang.org"
source: hosted
version: "9.0.4"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "3.7.0"
permission_handler_windows:
dependency: transitive
description:
name: permission_handler_windows
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
platform: platform:
dependency: transitive dependency: transitive
description: description:
@ -205,13 +165,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.2" version: "2.1.2"
provider:
dependency: "direct main"
description:
name: provider
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.3"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -280,13 +233,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.1" version: "2.1.1"
win32:
dependency: transitive
description:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.2"
sdks: sdks:
dart: ">=2.15.0 <3.0.0" dart: ">=2.15.0 <3.0.0"
flutter: ">=2.0.0" flutter: ">=2.8.0"

@ -34,11 +34,10 @@ dependencies:
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2 cupertino_icons: ^1.0.2
telephony: any telephony: ^0.1.4
provider: ^6.0.3
call_log: ^4.0.0 call_log: ^4.0.0
flutter_background_service: any flutter_background_service: ^0.2.6
device_info_plus: any permission_handler: ^10.0.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

Loading…
Cancel
Save