My App is crashing on android 11 when I store realm database locally in a folder?

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

My App is crashing on android 11 when I store realm database locally in a folder?

问题

以下是您提供的内容的翻译部分:

应用程序在 Android 11 上崩溃,当我尝试将 Realm 数据库保存在本地内部存储时。在所有其他版本中,应用程序都可以正常工作,但今天我将应用程序更新到了 Android 11,然后它就崩溃了。

E/AndroidRuntime: 致命异常: 主线程
进程:  PID: 7882
io.realm.exceptions.RealmError: 无法恢复的错误。在 io_realm_internal_Group.cpp 的第 210 行失败: 操作不允许
    at io.realm.internal.Group.nativeWriteToFile(Native Method)

private Realm realm;

try {

    File file = new File(folderPath);
    if (!file.exists()) {
        file.mkdir();
    }

    realm = new File(file, fileName);

    if (realm.exists()) {
        realm.delete();
    }

    realm.writeCopyTo(realm); // 在此行崩溃

} catch (IOException e) {
    e.printStackTrace();
}

请注意,上面的翻译只涉及您提供的代码和内容。如果您有任何其他翻译需求,请随时告诉我。

英文:

The app crashes on Android 11 when I am going to save realm database in local internal storage. The app is working in all other version but today I updated my app to android 11 and it's crashing.

E/AndroidRuntime: FATAL EXCEPTION: main
Process:  PID: 7882
io.realm.exceptions.RealmError: Unrecoverable error. open() failed: Operation not permitted in io_realm_internal_Group.cpp line 210
    at io.realm.internal.Group.nativeWriteToFile(Native Method)
    
   
      private Realm realm;

      try {

        File file = new File(folderPath);
        if (!file.exists()) {
            file.mkdir();
        }
      
        realm = new File(file, fileName);
       
        if (realm .exists()) {
            realm .delete();
        }
       
        realm.writeCopyTo(realm ); // crashing here in this line

    } catch (IOException e) {
        e.printStackTrace();
      
    }

答案1

得分: 1

存储权限在安卓 11 中发生了彻底的改变,涉及应用程序访问权限的方式。现在,应用程序无法访问除自己的数据目录之外的其他存储。一些无法在没有访问文件系统的情况下正常工作的应用程序,比如文件管理器,需要具有完全的文件访问权限
您的应用在安卓 11 上崩溃,很可能是因为它没有写入存储的权限。
更多信息 - 在此阅读

英文:

Storage permission is completely changed in android 11 as to how an app accesses it. Now apps can't access other storage other than their own data directories. Some apps which can't work without accessing the file system like File manager need to have all file access permission.
Your app is crashing in android 11, most probably because it doesn't have permission to write on storage.
For further info - Read here

答案2

得分: 0

在阅读文档后,我通过将getExternalStorageDirectory替换为context.getExternalFilesDir()来解决了这个问题,以便在本地文件夹中保存Realm数据库以备份。

查看文档

英文:

After reading the documentation I solved the issue by replacing getExternalStorageDirectory to context.getExternalFilesDir(); to save realm database locally in a folder for backup.

See Doc

答案3

得分: 0

getFilesDir()帮助我:

new RealmConfiguration.Builder().directory(getFilesDir())...

Environment.getExternalStorageDirectory()更改为getFilesDir()

英文:

getFilesDir() helps me:

new RealmConfiguration.Builder().directory(    getFilesDir()    )...

change Environment.getExternalStorageDirectory() to getFilesDir()

huangapple
  • 本文由 发表于 2020年9月28日 21:27:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/64103135.html
匿名

发表评论

匿名网友

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

确定