String path = null; if (getExternalCacheDir() != null) {//Determine whether external storage is available, that is, SD card //If there is one, use SD card#🎜🎜 # path = context.getExternalCacheDir().getAbsolutePath() + File.separator; } else { //Otherwise there is the phone’s own memory path= context.getCacheDir().getAbsolutePath( ) + File.separator; }
The above only writes to the root directory, you can create new directories according to your needs
getExternalCacheDir method context can be used directly in Application, or getExternalCacheDir can be called directly in Application
1. Create a folder to store pictures
2. Create a file to store pictures
3. Download pictures and write them into files
Download images and store them locally in main code
String path = null;
The above only writes to the root directory, you can create new directories according to your needsif (getExternalCacheDir() != null) {//Determine whether external storage is available, that is, SD card
//If there is one, use SD card#🎜🎜 # path = context.getExternalCacheDir().getAbsolutePath() + File.separator;
} else {
//Otherwise there is the phone’s own memory
path= context.getCacheDir().getAbsolutePath( ) + File.separator;
}