Step 1. Add it in your root build.gradle at the end of repositories(for Gradle 6.7 or lower):
allprojects {
repositories {
//...
maven { url 'https://jitpack.io' }
}
}
Or For API 33(Gradle 6.8 or higher) in settings.gradle
dependencyResolutionManagement {
//...
repositories {
//...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.arnab-kundu:Storage:1.0.5'
}
Step 3. Use this below code blocks as per your requirement into any of Activity, Fragment, ViewModel, Repository, FileManager etc.
- Create text file
val appFileManager = AppFileManager(BuildConfig.APPLICATION_ID)
appFileManager.createFile(
context = this,
fileLocationCategory = FileLocationCategory.MEDIA_DIRECTORY,
fileName = "TestFile",
fileExtension = "txt"
)
- Create folder
val appFileManager = AppFileManager(BuildConfig.APPLICATION_ID)
appFileManager.createFolder(
folderName = "SampleFolder",
path = filesDir.path
)
- Encrypt file
val appFileManager = AppFileManager(BuildConfig.APPLICATION_ID)
appFileManager.createFile(
context = this,
fileLocationCategory = FileLocationCategory.EXTERNAL_FILES_DIRECTORY,
fileName = "SampleFile",
fileExtension = "txt"
)
appFileManager.encryptFile(
context = this,
srcFilePath = filesDir.path+"/SampleFile.txt",
encryptedFileName = "MyEncrypt"
)
- Decrypt file
val appFileManager = AppFileManager(BuildConfig.APPLICATION_ID)
appFileManager.decryptFile(
context = this,
encryptedFilePath = "/storage/emulated/0/Android/media/${BuildConfig.APPLICATION_ID}/MyEncrypt.enc",
outputFileName = "MyDecryptFile.txt"
)
- Zip list of file
val inputPath = "/storage/emulated/0/Android/media/${BuildConfig.APPLICATION_ID}"
val listOfFiles = arrayListOf<String>()
listOfFiles.add("$inputPath/testFile.txt")
listOfFiles.add("$inputPath/testImage.jpeg")
listOfFiles.add("$inputPath/big_buck_bunny_240p_10mb.mp4")
fileManager.zipListOfFiles(listOfFiles, "$inputPath${File.separator}zipFileName.zip")
- Unzip file
val inputPath = "/storage/emulated/0/Android/media/${BuildConfig.APPLICATION_ID}"
fileManager.unZipFile(
zipFilePath = "/storage/emulated/0/Android/media/${BuildConfig.APPLICATION_ID}/10mb.zip",
extractLocationPath = "/storage/emulated/0/Android/media/${BuildConfig.APPLICATION_ID}/"
)
- Android Studio Iguana | 2023.2.1
- Minimum SDK version: 24
- Target SDK version: 34
- JDK version: 17
- Android 10
- Android 11
- Android 12
- android 13
- android 14