Anuradha Anuradha -3 years ago 352
Android Question

java.lang.SecurityException: MODE_WORLD_READABLE no longer supported with OPEN_READONLY

On trying to open sqlite db with the below statement

I am gettng the below error

java.lang.SecurityException: MODE_WORLD_READABLE no longer supported

But if I try to open db with OPEN_READWRITE its opening.

Could you please help me how to open the db with Read only mode.

Answer Source

You seem to be mixing the integer flags.

You're calling openOrCreateDatabase() method in Context. That method does not take in SQLiteDatabase flags but Context flags. The flags get interpreted differently and when your target SDK is Nougat or higher, you get this exception.

There's openDatabase() static method in SQLiteDatabase that takes in flags such as SQLiteDatabase.OPEN_READONLY | SQLiteDatabase.CREATE_IF_NECESSARY.

Consider using SQLiteOpenHelper though. It makes your database management easier, and you can just call getReadableDatabase() to indicate you want a read-only database.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download