【发布时间】:2014-11-13 05:37:26
【问题描述】:
我的应用程序允许用户浏览他们的文件系统以选择保存文件的位置。不幸的是,4.4 用户不再能够保存到外部 SD 卡。我在网上找到的所有解决方法都被称为“不是特别好的想法”,但其他应用程序目前已成功保存到外部 sd 卡,所以我认为这些解决方法正在使用中。
是否有解决此问题的安全/智能解决方法或推荐的最佳做法?
一些在 4.4.2 设备上引发异常的代码:
public class SdSample extends Activity
{
public void onCreate(Bundle bundle)
{
super.onCreate(bundle);
File external = new File("/storage/extSdCard/DCIM/");
File textFile = new File(external, "textfile.txt");
try
{
textFile.createNewFile();
FileOutputStream fos = new FileOutputStream(textFile);
fos.write("Hello".getBytes());
fos.close();
}
catch (Exception e)
{
//java.io.IOException: open failed: EACCES (Permission denied)
Log.e("", Log.getStackTraceString(e));
}
}
}
【问题讨论】:
标签: android