Skip to content

Commit

Permalink
Fix: permission manage External Storage
Browse files Browse the repository at this point in the history
  • Loading branch information
honjow committed Aug 3, 2021
1 parent 6f6a869 commit e05791b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ android {
defaultConfig {
applicationId "com.honjow.fehviewer"
minSdkVersion 21
targetSdkVersion 28
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
archivesBaseName = "feh-v$versionName+$versionCode"
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:requestLegacyExternalStorage="true"
android:label="FEhViewer"
android:icon="@mipmap/ic_launcher">
<activity
Expand All @@ -16,6 +17,7 @@
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:requestLegacyExternalStorage="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
Expand Down
27 changes: 27 additions & 0 deletions lib/common/controller/download_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:sprintf/sprintf.dart' as sp;

import 'download_state.dart';
Expand Down Expand Up @@ -105,18 +106,44 @@ class DownloadController extends GetxController {
}
}

Future<void> requestPermission() async {
final PermissionStatus statusMStorage =
await Permission.manageExternalStorage.status;
logger.d('manageExternalStorage $statusMStorage');
if (statusMStorage.isPermanentlyDenied) {
if (await Permission.manageExternalStorage.request().isGranted) {
return;
} else {
showToast('Permission is permanently denied, open App Settings');
openAppSettings();
logger.d('jump to setting');
}
} else {
if (await Permission.manageExternalStorage.request().isGranted) {
return;
} else {
throw 'Unable to download, please authorize first~';
}
}
}

/// 获取下载路径
Future<String> _getGalleryDownloadPath(String custpath) async {
late final String _dirPath;
late final Directory savedDir;
if (GetPlatform.isAndroid && ehConfigService.downloadLocatino.isNotEmpty) {
// 自定义路径
logger.d('自定义路径');
await requestPermission();
_dirPath = path.join(ehConfigService.downloadLocatino, custpath);
savedDir = Directory(_dirPath);
} else if (GetPlatform.isAndroid) {
logger.d('无自定义路径');
_dirPath = path.join(
(await getExternalStorageDirectory())!.path, 'Download', custpath);
savedDir = Directory(_dirPath);
} else {
logger.d('iOS');
// iOS 记录的为相对路径 不记录doc的实际路径
_dirPath = path.join('Download', custpath);
savedDir = Directory(path.join(Global.appDocPath, _dirPath));
Expand Down
7 changes: 3 additions & 4 deletions lib/network/gallery_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ class Api {
// 25个一组分割
List _group = EHUtils.splitList(_gidlist, 25);

List rultList = [];
final rultList = <dynamic>[];

// 查询 合并结果
for (int i = 0; i < _group.length; i++) {
Expand Down Expand Up @@ -620,8 +620,7 @@ class Api {
final _category = rultList[i]['category'] as String?;

// 标签
final List<String> tags =
rultList[i]['tags'].map((e) => e as String?).toList() as List<String>;
final List<dynamic> tags = rultList[i]['tags'] as List<dynamic>;
final _tagsFromApi = tags;

// 大小
Expand All @@ -641,7 +640,7 @@ class Api {
/// 判断获取语言标识
String _translated = '';
if (tags.isNotEmpty) {
_translated = EHUtils.getLangeage(tags[0]);
_translated = EHUtils.getLangeage(tags[0] as String);
}

galleryItems[i] = galleryItems[i].copyWith(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: fehviewer

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.1.20+268
version: 1.1.20+269

environment:
sdk: '>=2.13.0 <3.0.0'
Expand Down

0 comments on commit e05791b

Please sign in to comment.