Xamarin Forms,Android 11+,rote中的访问音乐文件夹

发布于 2025-01-30 19:09:34 字数 351 浏览 1 评论 0原文

嗨,我搜索并搜索了。

如何访问Android中的音乐文件夹? 不是该应用程序的音乐文件夹。

Android.os不可用。

我什至尝试了system.io.directory.getFiles(“/”);无许可。

我检查了陈述存储或阅读的清单中的所有许可。

我需要每个音频文件的filepath才能播放它。我不需要用户选择文件的文件对话框。

我需要root Music Dir中所有音频文件的字符串[]而不是应用程序。

必须有一种方法,因为存在音频播放器可以访问我的根部音乐文件夹。

不是 sdcard存储

Hi i searched and searched.

How do i access the music folder in android? Not the music folder of the app.

Android.OS is not available.

I even tried System.IO.Directory.GetFiles("/"); no permissions.

I checked every permission in the manifest that states storage or read.

I need the filepath to each audio file to be able to play it. I don't need a file dialog where the user chooses a file.

I need a string[] of all audio files in the root music dir not the app dir.

There has to be a way, cause audio players exist that access my root music folder.

NOT sdCard Storage

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

汹涌人海 2025-02-06 19:09:34

可能是您可以尝试授予您的应用程序访问所有文件的权限。

首先,将权限添加到AndroidManifest.xml中:

<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

然后将以下代码添加到主要活动的on Create方法中以请求许可。

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);
    Xamarin.Essentials.Platform.Init(this, savedInstanceState);
    global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
    LoadApplication(new App());
    if (!Android.OS.Environment.IsExternalStorageManager)
    {
        Intent intent = new Intent();
        intent.SetAction(Android.Provider.Settings.ActionManageAppAllFilesAccessPermission);
        Android.Net.Uri uri = Android.Net.Uri.FromParts("package", this.PackageName, null);
        intent.SetData(uri);
        StartActivity(intent);
    }
}

May be you can try to grant your app the permission about accessing all the files.

At first, add the permission into the AndroidManifest.xml:

<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

And then add the following code into the OnCreate method of the main activity to request the permission.

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);
    Xamarin.Essentials.Platform.Init(this, savedInstanceState);
    global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
    LoadApplication(new App());
    if (!Android.OS.Environment.IsExternalStorageManager)
    {
        Intent intent = new Intent();
        intent.SetAction(Android.Provider.Settings.ActionManageAppAllFilesAccessPermission);
        Android.Net.Uri uri = Android.Net.Uri.FromParts("package", this.PackageName, null);
        intent.SetData(uri);
        StartActivity(intent);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文