Skip to content

Commit

Permalink
Fix permission issues
Browse files Browse the repository at this point in the history
  • Loading branch information
doraemonkeys committed Jul 15, 2023
1 parent ee95793 commit 2f84e73
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
15 changes: 15 additions & 0 deletions flutter/clipboard/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!--Permissions for the Android below 11 (R)-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- Android 13-->
<!-- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="32" /> -->

<!--Permission for the Android 11 (R) and above-->
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<!-- Android 13-->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<application
android:label="clipboard-go"
android:name="${applicationName}"
Expand Down
5 changes: 5 additions & 0 deletions flutter/clipboard/lib/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ class FileUploader {
if (sentSize < 1024 * 100) {
var uselessData = List<int>.filled(1024 * 100 - sentSize, 0);
conn.add(uselessData);
try {
await conn.flush();
} catch (e) {
// print('flush error: $e');
}
}

// 下面的代码哪里有问题???
Expand Down
14 changes: 14 additions & 0 deletions flutter/clipboard/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import 'package:convert/convert.dart';
import 'package:intl/intl.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import 'package:flutter_toastr/flutter_toastr.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:device_info_plus/device_info_plus.dart';

import 'web.dart';
import 'file.dart';
Expand Down Expand Up @@ -1061,6 +1063,18 @@ class _HomePageState extends State<HomePage> {
{List<String>? filePath}) async {
final List<String> selectedFilesPath;
if (filePath == null || filePath.isEmpty) {
final androidInfo = await DeviceInfoPlugin().androidInfo;
// check permission
if (!await Permission.manageExternalStorage.request().isGranted) {
throw Exception('需要manageExternalStorage权限');
}
if (androidInfo.version.sdkInt > 32) {
if (!await Permission.photos.request().isGranted ||
!await Permission.videos.request().isGranted ||
!await Permission.audio.request().isGranted) {
throw Exception('需要photos, videos, audio权限');
}
}
final result = await FilePicker.platform.pickFiles(allowMultiple: true);
if (result == null || !result.files.isNotEmpty) {
throw Exception('No file selected');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import FlutterMacOS
import Foundation

import device_info_plus
import file_selector_macos
import path_provider_foundation

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
}
4 changes: 3 additions & 1 deletion flutter/clipboard/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 0.5.1
version: 0.5.0

environment:
sdk: ">=3.0.3 <4.0.0"
Expand Down Expand Up @@ -54,6 +54,8 @@ dependencies:
url: https://github.com/abhi16180/flutter_file_picker.git
ref: master
flutter_toastr: ^1.0.3
permission_handler: ^10.4.3
device_info_plus: ^8.2.2

dev_dependencies:
flutter_test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
#include "generated_plugin_registrant.h"

#include <file_selector_windows/file_selector_windows.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
FileSelectorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorWindows"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
}
1 change: 1 addition & 0 deletions flutter/clipboard/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
file_selector_windows
permission_handler_windows
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down

0 comments on commit 2f84e73

Please sign in to comment.