权限授予

dyb
戴余标 2 years ago
parent 5e53e777f5
commit b3fc551780

@ -31,6 +31,8 @@
android:name="flutterEmbedding"
android:value="2" />
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>

@ -109,19 +109,19 @@ class _MyAppState extends State<MyApp> {
// 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();
});
// 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 {

@ -1,12 +1,14 @@
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:permission_handler_platform_interface/permission_handler_platform_interface.dart';
import 'package:project_telephony/base/base_style.dart';
import 'package:project_telephony/main.dart';
import 'package:project_telephony/ui/widget/plone_back_button.dart';
import 'package:project_telephony/utils/headers.dart';
import 'package:telephony/telephony.dart';
class PrivacyRightsPage extends StatefulWidget {
final String name;
const PrivacyRightsPage({Key? key, required this.name}) : super(key: key);
@override
@ -22,6 +24,29 @@ final Telephony telephony = Telephony.instance;
// }
class _PrivacyRightsPageState extends State<PrivacyRightsPage> {
final Permission _permission = Permission.phone;
final PermissionHandlerPlatform _permissionHandler =
PermissionHandlerPlatform.instance;
PermissionStatus _permissionStatus = PermissionStatus.denied;
Future<void> requestPermission(Permission permission) async {
final status = await _permissionHandler.requestPermissions([permission]);
setState(() {
_permissionStatus = status[permission] ?? PermissionStatus.denied;
});
}
@override
void initState() {
super.initState();
_listenForPermissionStatus();
}
void _listenForPermissionStatus() async {
final status = await _permissionHandler.checkPermissionStatus(_permission);
setState(() => _permissionStatus = status);
}
@override
Widget build(BuildContext context) {
return Scaffold(
@ -67,47 +92,116 @@ class _PrivacyRightsPageState extends State<PrivacyRightsPage> {
// }
_getRights(bool pd) {
return GestureDetector(
onTap: () {},
child: Container(
height: 144.w,
width: 750.w,
padding: EdgeInsets.symmetric(horizontal: 64.w, vertical: 17.w),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'获取设备来电',
style: TextStyle(
fontSize: 32.sp,
color: BaseStyle.color333333,
fontWeight: FontWeight.bold),
),
16.hb,
Text('用于获取设备1',
style: TextStyle(
fontSize: 28.sp, color: BaseStyle.color999999)),
],
),
269.wb,
Text(pd ? "未允许" : "已允许",
style: TextStyle(
fontSize: 24.sp,
color: pd
? const Color(0xFFFF4D4D)
: BaseStyle.color999999)),
SizedBox(
width: 48.w,
height: 48.w,
child: const Icon(
Icons.keyboard_arrow_right,
),
),
],
)),
return ListView(
children: Permission.values
.where((permission) {
return permission == Permission.phone ||
permission == Permission.sms;
})
.map((permission) => PermissionWidget(permission))
.toList());
}
}
class PermissionWidget extends StatefulWidget {
const PermissionWidget(this._permission);
final Permission _permission;
@override
_PermissionState createState() => _PermissionState(_permission);
}
class _PermissionState extends State<PermissionWidget> {
_PermissionState(this._permission);
final Permission _permission;
final PermissionHandlerPlatform _permissionHandler =
PermissionHandlerPlatform.instance;
PermissionStatus _permissionStatus = PermissionStatus.denied;
List<String> title = [
"获取来电权限",
"获取短信权限",
];
List<String> sub = [
"用于监听来电状态",
"用于发送短信",
];
@override
void initState() {
super.initState();
_listenForPermissionStatus();
}
void _listenForPermissionStatus() async {
final status = await _permissionHandler.checkPermissionStatus(_permission);
setState(() => _permissionStatus = status);
}
Color getPermissionColor() {
switch (_permissionStatus) {
case PermissionStatus.denied:
return Colors.red;
case PermissionStatus.granted:
return Colors.green;
case PermissionStatus.limited:
return Colors.orange;
default:
return Colors.grey;
}
}
String getPermissionStu() {
switch (_permissionStatus) {
case PermissionStatus.denied:
return "未允许";
case PermissionStatus.granted:
return "已允许";
default:
return "未允许";
}
}
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(
_permission.value==8?title[0]:title[1],
style: Theme.of(context).textTheme.titleMedium,
),
subtitle: Text(
_permission.value==8?sub[0]:sub[1],
),
trailing: Wrap(
children: [
Text(getPermissionStu(),
style: TextStyle(color: getPermissionColor())),
const Icon(Icons.arrow_forward_ios),
],
),
onTap: () {
requestPermission(_permission);
},
);
}
void checkServiceStatus(
BuildContext context, PermissionWithService permission) async {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
(await _permissionHandler.checkServiceStatus(permission)).toString()),
));
}
Future<void> requestPermission(Permission permission) async {
final status = await _permissionHandler.requestPermissions([permission]);
setState(() {
print(status);
_permissionStatus = status[permission] ?? PermissionStatus.denied;
print(_permissionStatus);
});
}
}

@ -2,8 +2,8 @@ import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:permission_handler_platform_interface/permission_handler_platform_interface.dart';
import 'package:project_telephony/base/base_style.dart';
import 'package:project_telephony/ui/home/home_page.dart';
import 'package:project_telephony/ui/login/login_page.dart';
import 'package:project_telephony/ui/user/members_page.dart';
import 'package:project_telephony/ui/user/privacy_rights_page.dart';
@ -31,6 +31,8 @@ void initState() {}
class _UserPageState extends State<UserPage> {
bool vle = false;
bool tooken = true;
@override
Widget build(BuildContext context) {
return CloudScaffold(
@ -54,7 +56,8 @@ class _UserPageState extends State<UserPage> {
PloneBottom(
border: false,
onTap: () {
PermissionUtils.requestAllPermission()
PermissionUtils.requestAllPermission();
// Get.to(() => const HomePage());
},
textColor: const Color(0xFF1890FF),

@ -168,7 +168,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
color:
dependency: transitive
description:
@ -280,7 +280,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
ffi:
dependency: transitive
description:
@ -320,28 +320,7 @@ packages:
name: flutter_background_service
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.8+5"
flutter_background_service_android:
dependency: transitive
description:
name: flutter_background_service_android
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.2"
flutter_background_service_ios:
dependency: transitive
description:
name: flutter_background_service_ios
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.2"
flutter_background_service_platform_interface:
dependency: transitive
description:
name: flutter_background_service_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1+3"
version: "0.2.6"
flutter_gen_core:
dependency: transitive
description:
@ -369,7 +348,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:
@ -435,7 +414,7 @@ packages:
name: grinder
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.2"
version: "0.9.1"
hive:
dependency: "direct main"
description:
@ -533,7 +512,7 @@ packages:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
version: "0.6.4"
json_annotation:
dependency: "direct main"
description:
@ -582,7 +561,7 @@ packages:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "0.1.4"
meta:
dependency: transitive
description:
@ -617,7 +596,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
path_provider:
dependency: transitive
description:
@ -631,7 +610,7 @@ packages:
name: path_provider_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.17"
version: "2.0.12"
path_provider_ios:
dependency: transitive
description:
@ -689,7 +668,7 @@ packages:
source: hosted
version: "9.0.4"
permission_handler_platform_interface:
dependency: transitive
dependency: "direct main"
description:
name: permission_handler_platform_interface
url: "https://pub.dartlang.org"
@ -820,7 +799,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:
@ -853,7 +832,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
sp_util:
dependency: transitive
description:
@ -902,7 +881,7 @@ packages:
name: telephony
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
version: "0.2.0"
term_glyph:
dependency: transitive
description:
@ -916,7 +895,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.8"
version: "0.4.9"
time:
dependency: transitive
description:
@ -958,7 +937,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
velocity_x:
dependency: "direct main"
description:
@ -1016,5 +995,5 @@ packages:
source: hosted
version: "3.1.1"
sdks:
dart: ">=2.16.1 <3.0.0"
flutter: ">=2.8.1"
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.8.0"

@ -34,7 +34,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
telephony: ^0.1.4
telephony: ^0.2.0
## 获取来电状态
# provider: ^6.0.3
# 获取通话记录
@ -68,6 +68,8 @@ dependencies:
flustars: ^2.0.1
# model生成
json_annotation: ^4.6.0
permission_handler_platform_interface: ^3.7.0
# # jdk
# jverify: ^2.2.5
## pub 集成

Loading…
Cancel
Save