Skip to content

An open-source cross-platform alternative to AirDrop

fix: add permission handler for older android phones

Tien Do Namc70e45806a28
diff --git a/android/app/build.gradle b/android/app/build.gradle
index 4920441e..24163773 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -54,7 +54,7 @@ android {
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
- targetSdkVersion flutter.targetSdkVersion
+ targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index a524ae67..fd9ba0d8 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -1,9 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.localsend.localsend_app">
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- <application
+ <application
android:label="LocalSend"
android:name="${applicationName}"
android:usesCleartextTraffic="true"
diff --git a/lib/util/file_saver.dart b/lib/util/file_saver.dart
index 10e8c000..a617cf74 100644
--- a/lib/util/file_saver.dart
+++ b/lib/util/file_saver.dart
@@ -1,6 +1,7 @@
import 'dart:io';
import 'package:image_gallery_saver/image_gallery_saver.dart';
+import 'package:permission_handler/permission_handler.dart';
/// Saves the data [stream] to the [destinationPath].
/// [onProgress] will be called on every 100 KB.
@@ -10,6 +11,12 @@ Future<void> saveFile({
required Stream<List<int>> stream,
required void Function(int savedBytes) onProgress,
}) async {
+ try {
+ await Permission.storage.request();
+ } catch (e) {
+ print(e);
+ }
+
final sink = File(destinationPath).openWrite();
try {
int lastNotifyBytes = 0;
diff --git a/pubspec.lock b/pubspec.lock
index 7f0028d1..f4f2b388 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -571,6 +571,41 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
+ permission_handler:
+ dependency: "direct main"
+ description:
+ name: permission_handler
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "10.2.0"
+ permission_handler_android:
+ dependency: transitive
+ description:
+ name: permission_handler_android
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "10.2.0"
+ permission_handler_apple:
+ dependency: transitive
+ description:
+ name: permission_handler_apple
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "9.0.7"
+ permission_handler_platform_interface:
+ dependency: transitive
+ description:
+ name: permission_handler_platform_interface
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "3.9.0"
+ permission_handler_windows:
+ dependency: transitive
+ description:
+ name: permission_handler_windows
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "0.1.2"
petitparser:
dependency: transitive
description:
diff --git a/pubspec.yaml b/pubspec.yaml
index bc5fe301..b3865c55 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -25,6 +25,7 @@ dependencies:
network_info_plus: 3.0.1
package_info_plus: 3.0.2
path_provider: 2.0.11
+ permission_handler: 10.2.0
routerino: 0.2.0
shared_preferences: 2.0.15
shelf: 1.4.0
diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc
index f5e789c8..f27f443f 100644
--- a/windows/flutter/generated_plugin_registrant.cc
+++ b/windows/flutter/generated_plugin_registrant.cc
@@ -7,6 +7,7 @@
#include "generated_plugin_registrant.h"
#include <network_info_plus/network_info_plus_windows_plugin.h>
+#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
#include <window_manager/window_manager_plugin.h>
@@ -14,6 +15,8 @@
void RegisterPlugins(flutter::PluginRegistry* registry) {
NetworkInfoPlusWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("NetworkInfoPlusWindowsPlugin"));
+ PermissionHandlerWindowsPluginRegisterWithRegistrar(
+ registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
ScreenRetrieverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake
index eb6cef4e..566fc918 100644
--- a/windows/flutter/generated_plugins.cmake
+++ b/windows/flutter/generated_plugins.cmake
@@ -4,6 +4,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
network_info_plus
+ permission_handler_windows
screen_retriever
url_launcher_windows
window_manager