Android various file paths, and the problem that the skin plugin apk is cleaned up

I encountered a huge bug when doing apk plug-in skinning. In the case of insufficient mobile phone memory, I put the apk plug-in installation package in the data/data/package name/cache directory and deleted it, /(ㄒoㄒ )/~~, I also encountered a similar problem when I was working on a project in the summer vacation. After checking the relevant information, I found this

So the apk I put in the chache directory will be cleared

Then I have to find another way to put it in the /data/data/package name/files directory and try it, and then I will be cleared. . Hey, this thread will be updated continuously

The relevant knowledge is as follows


1、File cacheDir = context.getCacheDir();

The application's internal storage space (data file private) files are stored in this path, and there is no need to apply for permission. When the application is uninstalled, the files in the directory will be deleted.
It should be noted that the directory of this file is related to the storage location of the application.
When the application is moved to an external storage device, the absolute path of the file also changes, so it is recommended to use a relative path when storing data in this directory.
The biggest difference between this directory and the getFilesDir() directory is that when the storage space of the Android device is low or insufficient, the system will automatically delete the files in this directory.
The official recommendation is that files over 1MB should be stored in the getExternalCacheDir() directory

2、File filesDir = context.getFilesDir();

The application's internal storage space (data file private) files are stored in this path, and there is no need to apply for permission. When the application is uninstalled, the files in the directory will be deleted.
It should be noted that the directory of this file is related to the storage location of the application. When the application is moved to an external storage device, the absolute path of the file also changes, so it is recommended to use the relative path system
when storing data in this directory.
The provided method to access the file at this path is: context.openFileOutput(String,int);context.openFileInput(String name);

 

3、File externalCacheDir = context.getExternalCacheDir();

Application external storage space (data files are private, system media files cannot be accessed (for example, an MP3 file is stored, which cannot be found through the system's folder management system)),
when the application is uninstalled, the files in the directory will be deleted, But here is different from getCacheDir():
only when the mobile phone system uses virtual external storage (virtual SD card, most mobile phones now do not need external physical SD card), you
can uninstall the application. At the same time, the files in this directory are automatically deleted. If it is the previous physical storage (physical SD card), the directory and the files in the directory will not be automatically deleted.
When using it, you need to judge the mount status of the external storage (getExternalStorageState(File)), and you need to apply for read and write permissions (READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE).
Note: When other applications have SD card read and write permissions, they can access this directory. document

 

4、File externalFilesDir = context.getExternalFilesDir(null);

Application external storage space (data files are private, system media files cannot be accessed (for example, an MP3 file is stored, which cannot be found through the system's folder management system)),
when the application is uninstalled, the files in the directory will be deleted, But here is different from getFilesDir():
only when the mobile phone system uses virtual external storage (virtual SD card),
the files in this directory can be automatically deleted when the application is uninstalled. Storage (physical SD card) will not automatically delete the directory and the files
in the directory. When using it, you need to determine the mount status of the external storage (getExternalStorageState(File)), and you need to apply for read and write permissions (READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE)
Note: When other applications have SD card read and write permissions, they can access files in this directory

 

5、File externalStorageDirectory = Environment.getExternalStorageDirectory();

Application external storage space (data files are not private and can be accessed by the system programs of the mobile phone (such as files in MP3 format, which will be retrieved by the mobile phone system). Similarly, the files in this directory, all APP programs can also be accessed. ,)
Note: The external storage space may be in an inaccessible state, or it may have been removed, or the storage space may be damaged and inaccessible. You can use the getExternalStorageState() method to determine the state of the external storage space.
Note: To read and write files in this directory, you need to obtain read and write permissions
. The files in this directory are a root directory for users to operate. To enter the secondary directory, you can use
getExternalFilesDirs(String), getExternalCacheDirs(), and getExternalMediaDirs( ).These methods are
officially recommended not to use this directory directly. In order to avoid polluting the user's root namespace, application private data should be placed in the Context.getExternalFilesDir directory.
Other files that can be shared can be placed in getExternalStoragePublicDirectory(String) .Under contents

 

6.File externalStoragePublicDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

Application external storage space (data files are not private and can be accessed by the system programs of the mobile phone (such as files in MP3 format, which will be retrieved by the mobile phone system). Similarly, the files in this directory, all APP programs can also be accessed ,)
This directory is used to store various types of files, where users can classify and manage different types of files (such as music, pictures, movies, etc.); the
types are as follows: DIRECTORY_MUSIC, DIRECTORY_PODCASTS, DIRECTORY_RINGTONES, DIRECTORY_ALARMS, DIRECTORY_NOTIFICATIONS, DIRECTORY_PICTURES , DIRECTORY_MOVIES, DIRECTORY_DOWNLOADS, DIRECTORY_DCIM, or DIRECTORY_DOCUMENTS

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324736829&siteId=291194637