最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Android API 35 Context.openFileOutput() generates IOException - Stack Overflow

programmeradmin3浏览0评论

My (self-developed) Sudoku application generated an IOException (EACCES (Permission denied)) when I started using an API 35 emulated device in Android Studio. The problem did not occur using an API 34 emulated device. The problem occurred (among other places) in the following function when calling context.openFileOutput():

   void save(Context context, String fileName) {
  // Write the field as XML.
  String xmlFileName = fileName.endsWith(EXT_XML) ? fileName : fileName
        + EXT_XML;
  FileOutputStream xmlFos;
  try {
     xmlFos = context.openFileOutput(xmlFileName, Context.MODE_PRIVATE);
  } catch (IOException ex) {
     throw new RuntimeException(ex.getMessage());
  }
  serializeXml(xmlFos);

}

My (self-developed) Sudoku application generated an IOException (EACCES (Permission denied)) when I started using an API 35 emulated device in Android Studio. The problem did not occur using an API 34 emulated device. The problem occurred (among other places) in the following function when calling context.openFileOutput():

   void save(Context context, String fileName) {
  // Write the field as XML.
  String xmlFileName = fileName.endsWith(EXT_XML) ? fileName : fileName
        + EXT_XML;
  FileOutputStream xmlFos;
  try {
     xmlFos = context.openFileOutput(xmlFileName, Context.MODE_PRIVATE);
  } catch (IOException ex) {
     throw new RuntimeException(ex.getMessage());
  }
  serializeXml(xmlFos);

}

Share Improve this question edited Mar 30 at 11:01 David Singleton asked Mar 30 at 10:15 David SingletonDavid Singleton 1246 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I found the cause using the Android ADB shell function. I had uploaded a series of test files to the emulated device using a script I had developed. When I listed the files using the shell, I noticed that group access was only 'r' - readable. Changing the group access to 'rw' with the following command in the ADB shell solved my problem.

chmod g+w *

Obviously there has been some internal change in the Android OS between API 34 and API 35 that has resulted in my problem.

发布评论

评论列表(0)

  1. 暂无评论