一个安全的路径到外部存储路径、安全

2023-09-04 03:57:57 作者:超级英雄°

有关我的应用程序,我需要被存储在用户的设备上的一个相当大的数据库。我打算改变这在未来。但就目前而言,我想将它存储到用户的外部存储(如果有的话),而不是填补他们的内部存储。我可以用什么方法来获得一个安全的(意思是,适用于大多数的设备)路径到外部存储?

For my app, I have a fairly large database that needs to be stored on the user's device. I plan to change this in the future. For now, however, I'd like to store it to the user's external storage (if available) rather than fill up their internal storage. What method can I use to get a safe (meaning, will work on most devices) path to the external storage?

推荐答案

您可以得到的根路径来存储DATAS。我认为这将是最安全的情况下。

You could get the root path to store your datas. I think it will be the most secure case.

String root = Environment.getExternalStorageDirectory().toString();
File dir = new File(root + "/your_folder");
dir.mkdirs();
dir.setReadOnly();