mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
Add basic files selector
This required to add a platform channel with a method to get the toplevel storage devices. The app will need to request the WRITE_EXTERNAL_STORAGE permission later. Also the dependency on "path" was introduced.
This commit is contained in:
parent
02e283b8cc
commit
24a4911665
4 changed files with 213 additions and 2 deletions
|
|
@ -1,6 +1,8 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="de.johrpan.musicus">
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:name="io.flutter.app.FlutterApplication"
|
||||
android:label="Musicus"
|
||||
|
|
|
|||
|
|
@ -1,12 +1,39 @@
|
|||
package de.johrpan.musicus
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import io.flutter.plugins.GeneratedPluginRegistrant
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
class MainActivity : FlutterActivity() {
|
||||
private val CHANNEL = "de.johrpan.musicus/platform"
|
||||
|
||||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
|
||||
GeneratedPluginRegistrant.registerWith(flutterEngine);
|
||||
GeneratedPluginRegistrant.registerWith(flutterEngine)
|
||||
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
|
||||
if (call.method == "getStorageRoots") {
|
||||
result.success(getStorageRoots())
|
||||
} else {
|
||||
result.notImplemented()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getStorageRoots(): ArrayList<String> {
|
||||
val result = ArrayList<String>()
|
||||
|
||||
ContextCompat.getExternalFilesDirs(this, null).forEach {
|
||||
val path = it.absolutePath;
|
||||
val index = path.lastIndexOf("/Android/data/")
|
||||
|
||||
if (index > 0) {
|
||||
result.add(path.substring(0, index))
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue