Learning Android together

In Android development, the way of storage varies according to specific needs, such as whether the data is private to the application or accessible to other applications (and users), and how much space is needed to save the data.

The main storage methods are as follows (the first three are mainly involved in this paper):

The knowledge points involved are as follows:

In this way, only simple data types can be saved, as shown in the following figure:

The code is as follows:

The data content is saved in the file by converting it into bytes, as shown in the following figure:

The code is as follows:

In the external storage, you need to configure the relevant read and write permissions in androidmanifest.xml, as shown below:

Save in SD card, as shown in the following figure:

The code is as follows:

During external storage, if the storage space permission of the app is turned off by default and the application permission is not set, even if the permission is normally registered in the manifest, the app still makes it impossible to read and write files. The commissioning log is as follows:

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

Storage permission of app is not enabled 04-02 21:21:59.173 30863-30863/com.hex.demostorage I / demostorage: externalsave: start 04-02 21:21:59.407 30863-30863 / com.hex.demostorage I / demostorage: externalsave: saveimg 04-02 21:21:59.408 30863-30863 / com.hex.demostorage I / demostorage: saveimg: start 04-02 21:21:59.412 30863-30863 / com.hex.demostorage I / demostorage : saveimg: Path: / storage / emulated / 0 / hex / images 04-02 21:21:59.412 30863-30863 / com.hex.demostorage I / demostorage: saveimg: judgment path: OK 04-02 21:21:59.412 30863-30863 / com.hex.demostorage I / demostorage: saveimg: judgment file: 2 04-02 21:21:59.414 30863-30863 / com.hex.demostorage I / demostorage: saveimg: exception: no such file or directory 04- 02 21:21:59.414 30863-30863/com.hex.demostorage I / demostorage: externalsave: saveimg: false 04-02 21:21:59.414 30863-30863 / com.hex.demostorage I / demostorage: externalsave: end the storage permission to open the app 04-02 21:22:48.519 31306-31306 / com.hex.demostorage I / demostorage: externalsave: start 04-02 21:22:48.754 31306-31306 / com.hex.demostorage I / demost Orage: externalsave: saveimg 04-02 21:22:48.755 31306-31306 / com.hex.demostorage I / demostorage: saveimg: start 04-02 21:22:48.759 31306-31306 / com.hex.demostorage I / demostorage: saveimg: Path: / storage / emulated / 0 / hex / images 04-02 21:22:48.760 31306-31306 / com.hex.demostorage I / demostorage: saveimg: judgment path: OK 04-02 21:22:48.760 31306-31306 /Com.hex.demostorage I / demostorage: saveimg: judgment file: 2 04-02 21:22:48.761 31306-31306 / com.hex.demostorage I / demostorage: saveimg: judgment file: OK 04-02 21:22:48.763 31306-31306 / com.hex.demostorage I / demostorage: externalsave: saveimg: true 04-02 21: 22:48.787 31306-31306 / com.hex.demostorage I / demostorage: externalsave: end

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

Record learning, record growth!

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
分享
二维码
< <上一篇
下一篇>>