♻️ Refactor andoird default folder

This commit is contained in:
niuhuan 2023-03-22 16:38:30 +08:00
parent 1661a884ca
commit b5c4837076
4 changed files with 27 additions and 15 deletions

View File

@ -49,10 +49,8 @@
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" /> <data android:scheme="https" />
<data android:scheme="http" /> <data android:scheme="http" />
<data android:host="pika" /> <data android:host="pika" />
@ -63,8 +61,6 @@
<category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="pika" /> <data android:scheme="pika" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW"></action> <action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category> <category android:name="android.intent.category.DEFAULT"></category>
@ -78,6 +74,12 @@
<data android:pathPattern=".*\..*\..*\..*\.pkz"></data> <data android:pathPattern=".*\..*\..*\..*\.pkz"></data>
<data android:pathPattern=".*\..*\..*\..*\..*\.pkz"></data> <data android:pathPattern=".*\..*\..*\..*\..*\.pkz"></data>
<data android:pathPattern=".*\..*\..*\..*\..*\..*\.pkz"></data> <data android:pathPattern=".*\..*\..*\..*\..*\..*\.pkz"></data>
<data android:pathPattern=".*\.pki"></data>
<data android:pathPattern=".*\..*\.pki"></data>
<data android:pathPattern=".*\..*\..*\.pki"></data>
<data android:pathPattern=".*\..*\..*\..*\.pki"></data>
<data android:pathPattern=".*\..*\..*\..*\..*\.pki"></data>
<data android:pathPattern=".*\..*\..*\..*\..*\..*\.pki"></data>
<data <data
android:host="*" android:host="*"
android:mimeType="*/*" android:mimeType="*/*"
@ -88,6 +90,12 @@
<data android:pathPattern=".*\..*\..*\..*\.pkz"></data> <data android:pathPattern=".*\..*\..*\..*\.pkz"></data>
<data android:pathPattern=".*\..*\..*\..*\..*\.pkz"></data> <data android:pathPattern=".*\..*\..*\..*\..*\.pkz"></data>
<data android:pathPattern=".*\..*\..*\..*\..*\..*\.pkz"></data> <data android:pathPattern=".*\..*\..*\..*\..*\..*\.pkz"></data>
<data android:pathPattern=".*\.pki"></data>
<data android:pathPattern=".*\..*\.pki"></data>
<data android:pathPattern=".*\..*\..*\.pki"></data>
<data android:pathPattern=".*\..*\..*\..*\.pki"></data>
<data android:pathPattern=".*\..*\..*\..*\..*\.pki"></data>
<data android:pathPattern=".*\..*\..*\..*\..*\..*\.pki"></data>
</intent-filter> </intent-filter>
</activity> </activity>
<!-- Don't delete the meta-data below. <!-- Don't delete the meta-data below.

View File

@ -102,6 +102,7 @@ class MainActivity : FlutterActivity() {
"androidGetExtendDirs" -> androidGetExtendDirs() "androidGetExtendDirs" -> androidGetExtendDirs()
"androidSecureFlag" -> androidSecureFlag(call.argument("flag")!!) "androidSecureFlag" -> androidSecureFlag(call.argument("flag")!!)
"verifyAuthentication" -> auth() "verifyAuthentication" -> auth()
"androidStorageRoot" -> storageRoot()
else -> { else -> {
notImplementedToken notImplementedToken
} }
@ -404,5 +405,7 @@ class MainActivity : FlutterActivity() {
return queue.poll(5, TimeUnit.MINUTES) ?: false return queue.poll(5, TimeUnit.MINUTES) ?: false
} }
fun storageRoot(): String {
return Environment.getExternalStorageDirectory().absolutePath
}
} }

View File

@ -972,4 +972,8 @@ class Method {
String ms = await _flatInvoke("ping", idx); String ms = await _flatInvoke("ping", idx);
return int.parse(ms); return int.parse(ms);
} }
Future<String> androidStorageRoot() async {
return await _channel.invokeMethod("androidStorageRoot");
}
} }

View File

@ -7,13 +7,16 @@ import 'package:permission_handler/permission_handler.dart';
import '../Common.dart'; import '../Common.dart';
import '../Method.dart'; import '../Method.dart';
import 'Platform.dart';
const _propertyName = "chooserRoot"; const _propertyName = "chooserRoot";
late String _chooserRoot; late String _chooserRoot;
late String _androidDefaultRoot;
Future<dynamic> initChooserRoot() async { Future<dynamic> initChooserRoot() async {
_chooserRoot = await method.loadProperty(_propertyName, ""); _chooserRoot = await method.loadProperty(_propertyName, "");
if (Platform.isAndroid) {
_androidDefaultRoot = await method.androidStorageRoot();
}
} }
String _currentChooserRoot() { String _currentChooserRoot() {
@ -25,7 +28,7 @@ String _currentChooserRoot() {
} else if (Platform.isLinux) { } else if (Platform.isLinux) {
return '/'; return '/';
} else if (Platform.isAndroid) { } else if (Platform.isAndroid) {
return '/storage/emulated/0'; return _androidDefaultRoot;
} else { } else {
return ''; return '';
} }
@ -35,14 +38,8 @@ String _currentChooserRoot() {
Future<String> currentChooserRoot() async { Future<String> currentChooserRoot() async {
if (Platform.isAndroid) { if (Platform.isAndroid) {
if (androidVersion >= 30) { if (!(await Permission.storage.request()).isGranted) {
if (!(await Permission.manageExternalStorage.request()).isGranted) { throw Exception("申请权限被拒绝");
throw Exception("申请权限被拒绝");
}
} else {
if (!(await Permission.storage.request()).isGranted) {
throw Exception("申请权限被拒绝");
}
} }
} }
return _currentChooserRoot(); return _currentChooserRoot();