我的根目录在安卓10中没有被创建?

huangapple go评论91阅读模式
英文:

My Root Folder isn't create in android 10?

问题

我下载音乐并希望在我的回收站中播放,所有安卓设备上都正常,但在安卓10上未能创建根目录。以下是我的代码:

 File parent = new File(Environment.getExternalStorageDirectory().toString(), ".RingTones2020");
final String songPath = "/" + arrayListNames[pos] + ".mp3";
final String loc = parent + songPath;
final File checkFile = new File(parent, songPath);

请帮助我...

英文:

I Download music and want to play in my recycler, everything is ok in all android but in android 10 the root isn't created, here is my code :

     File parent = new File(Environment.getExternalStorageDirectory().toString(), ".RingTones2020");
    final String songPath = "/" + arrayListNames[pos] + ".mp3";
    final String loc = parent + songPath;
    final File checkFile = new File(parent, songPath);

Please Help me...

答案1

得分: 1

getExternalStorageDirectory在Android 10中已被弃用,您应该查看访问存储的新限制,称为Scoped Storage。仅适用于Android 10,您可以选择退出并在清单中添加requestLegacyExternalStorage标志,但Scoped Storage将在Android 11及更高版本中变为强制性。

英文:

getExternalStorageDirectory is deprecated in Android 10, you should check out new restrictions for accessing storage called Scoped Storage. for just Android 10 you can opt out and add requestLegacyExternalStorage flag to manifest, but Scoped Storage will be mandatory in Android 11 and above

答案2

得分: 1

在 Api 级别 29 中,此方法已被弃用。
您无法直接访问用户的存储。
如果您想要保存任何文件,有一些基于您的用例的方法。

  1. 作用域存储(其他应用无法访问)
  2. 使用 MediaStore(用于媒体文件)

详细信息请参见此处

英文:

In Api level 29 this method is deprecated..
You can't access the user's storage directly..
If you want to save any files, there will be few ways based on your use cases..

  1. Scoped storage (not accessible for other apps)
  2. Using MediaStore (for media files)

See here for more details

huangapple
  • 本文由 发表于 2020年9月7日 20:37:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/63777807.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定