Method of writing Android database SQLite to SD card

If the mobile phone does not have root, the database file cannot be viewed, which is inconvenient for debugging.

The best way is to write the database into the SD card.

There are two modifications:

1. Put the database file name database in your helper class_ Name is changed from the original file name to the form of path.

Before modification: Database_ NAME = "demo.db"

Modified: Database_ NAME = "/mnt/sdcard/demo.db"

Because if it is just a separate file name, the database file created last is saved in the / data / package name / databases directory of the internal memory card of the mobile phone (neither running memory nor SD card). For mobile phones without root, the / data root folder cannot be accessed and cannot be opened by ADB shell.

2. Finally, don't forget to modify permissions!

Android phones have strict security control. The SD card belongs to external memory. You need to add permissions to access the above files.

Add two SD card read / write permissions to androidmanifest.xml:

If you do not add permissions, the program will terminate abnormally.

The above is the method of writing SD card to Android database SQLite. I hope it will be helpful to you!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>