Code Monkey home page Code Monkey logo

android-storage's Introduction

android-storage

Library to create, read, delete, append, encrypt files and more, on internal or external disk spaces with a really simple API.

Latest Release

Download

dependencies {
    compile 'com.snatik:storage:2.1.0'
}

Don't forget to update AndroidManifest.xml and add next line:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Usage

// init
Storage storage = new Storage(getApplicationContext());

// get external storage
String path = storage.getExternalStorageDirectory();

// new dir
String newDir = path + File.separator + "My Sample Directory";
storage.createDirectory(newDir);

Check all options, scroll down ;)

Sample app

The app has some simple UI screens and uses the storage library. This is just an example of what can be done with this lib.

Options

Initialize

Storage storage = new Storage(getApplicationContext());

Work on External Storage.

  • Check if external writable

     boolean isWritable = storage.isExternalWritable();
  • Root external storage path

     String path = storage.getExternalStorageDirectory();
  • If you want to use a particular public directory

    Storage storage = SimpleStorage.getExternalStorage(Environment.DIRECTORY_PICTURES);

Work on Internal Storage.

  • Directory for storing app internal files (documentation):

     String path = SimpleStorage.getInternalFilesDirectory();
  • Cache dir

     String path = SimpleStorage.getInternalCacheDirectory();
  • Root internal storage dir

     String path = SimpleStorage.getInternalRootDirectory();

Create directory

  • Create directory

     storage.createDirectory(path);
  • Create directory and override the existing one.

     storage.createDirectory(path, true);

Create file

Create a new file with the content in it.

storage.createFile(path, "some content of the file");

The content of the file can be one of the next types:

  • String
  • byte[]
  • Bitmap
  • Storable

Read file

Read the content of any file to byte array.

byte[] bytes = storage.readFile(path);

Read the content of the file to String.

String content = storage.readTextFile(path);

Append content to file

storage.appendFile(path, "more new data");

You can append:

  • String
  • byte[]

Copy

storage.copy(fromPath, toPath);

Move

storage.move(fromPath, toPath);

Delete directory

storage.deleteDirectory(path);

Delete file

storage.deleteFile(path);

Get files

  • Get files in ordered way by: name, date, size

     List<File> files = storage.getFiles(path, OrderType.DATE);
  • Get files and filter by regular expression:

     String regex = ...;
     List<File> files = storage.getFiles(path, regex);
  • Get all nested files (without the directories)
     List<File> files = storage.getNestedFiles(path);

More...

  • Is directory exists

     boolean dirExists = storage.isDirectoryExists(path);
  • Is file exists

     boolean fileExists = storage.isFileExist(path);

Security configuration

You can write and read files while the content is encrypted. It means, that no one can read the data of your files from external or internal storage.

You will continue using the same api as before. The only thing you need to do is to configure the Simple Storage library before the you want to create/read encrypted data.

// set encryption
String IVX = "abcdefghijklmnop"; // 16 lenght - not secret
String SECRET_KEY = "secret1234567890"; // 16 lenght - secret
byte[] SALT = "0000111100001111".getBytes(); // random 16 bytes array

// build configuratio
EncryptConfiguration configuration = new EncryptConfiguration.Builder()
	.setEncryptContent(IVX, SECRET_KEY, SALT)
	.build();
	
// configure the simple storage
storage.setEncryptConfiguration(configuration);

Now, you can create a new file with content and the content will be automatically encrypted.
You can read the file and the content will be decrypted.

Example

Create file with next content "this is the secret data":

storage.setEncryptConfiguration(configuration);
storage.createFile(path, "this is the secret data");

If we open the file to see it's content then it we will something like this: „f°α�ΤG†_i�ΐp . It looks good :)

And now, read the file data with the same api:

storage.setEncryptConfiguration(configuration);
String content = storage.readTextFile(path);

You will see that the content will be: "this is the secret data".

Tests

Just play and check the sample app ;)

android-storage's People

Contributors

chemickypes avatar ericcumbee avatar sohaibshaheen avatar sromku avatar stephanebg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-storage's Issues

return File

Hello is there a way I can cast createFile to return a string so I can pass it to File.

something like new File(createFile("path"))

Impossible to read encrypted file after application restard

The library is working fine, I can encrypt and open file without any issues during one app lifetime.

But when I open my application again, I can't read the file I have encrypted Iast time, even when I am using the same IVX, SECRET_KEY, and SALT the both times.

What Sould I do ?

Regards,

isDirectoryExists method creates directory instead of just checking up

What you should do to reproduce the bug
Storage storage = SimpleStorage.getInternalStorage(context); Log.e("1", "does " + DIR_PATH + " exist " + storage.isDirectoryExists(DIR_PATH);
Always returns true, because this method actually creates the dir.

Why does this happen?
AbstractDiskStorage invokes buildPath(name) inside isDirectoryExists(String name).
buildPath(name) has context.getDir(directoryName, Context.MODE_PRIVATE) in InternalStorage implementation.
getDir method creates the dir if it does not already exist.

Failed to encrypt/descrypt

Hi,

first of all thank you for the great library.

When I try to read a previously (crypted) stored text file I get those exception.

W/System.err: java.lang.RuntimeException: Failed to encrypt/descrypt
W/System.err:     at com.sromku.simple.storage.security.SecurityUtil.encrypt(SecurityUtil.java:79)
W/System.err:     at com.sromku.simple.storage.AbstractDiskStorage.encrypt(AbstractDiskStorage.java:411)
W/System.err:     at com.sromku.simple.storage.AbstractDiskStorage.readFile(AbstractDiskStorage.java:386)
W/System.err:     at com.sromku.simple.storage.AbstractDiskStorage.readFile(AbstractDiskStorage.java:161)
W/System.err:     at com.sromku.simple.storage.InternalStorage.readFile(InternalStorage.java:18)
W/System.err:     at com.sromku.simple.storage.AbstractDiskStorage.readTextFile(AbstractDiskStorage.java:169)
W/System.err:     at com.sromku.simple.storage.InternalStorage.readTextFile(InternalStorage.java:18)

which is caused by

W/System.err: Caused by: javax.crypto.BadPaddingException: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt

The keys are exactly the same as they were used for writing the file.

Thanks,
Moritz

Issue In AbstractDiskStorage

Hi sromku ,

I face an issue in class AbstractDiskStorage specially in createDirectory

the line if (isDirectoryExists(path)) i thin you should pass name not path as you make buildPath Inside the method that cause duplication in the root path

Mount path /storage/emulated/0

when i get mount path of micro SD card on my device(LG 4C), it gives me "/storage/9C5E-C37F/", but this library generates the mount path like this "/storage/emulated/0" for getExternalStorage() method.
Any solution ?

Saving to subfolder on internal storage causes crash

Getting a fatal exception when trying to save a Bitmap to a subfolder in the internal storage. i.e.
INTERNAL_STORAGE/31/public/12jpg

Code:
Storage storage = SimpleStorage.getInternalStorage(context); storage.createFile(contact.getId() + "/public", nextFileName, originalFileAsBitmap);

Error:
07-25 21:55:13.283 1982-1982/net.gazeapp E/AndroidRuntime: FATAL EXCEPTION: main Process: net.gazeapp, PID: 1982 java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2000, result=-1, data=Intent { (has extras) }} to activity {net.gazeapp/net.gazeapp.AddContactActivity_}: java.lang.IllegalArgumentException: File app_31/public contains a path separator at android.app.ActivityThread.deliverResults(ActivityThread.java:3699) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742) at android.app.ActivityThread.-wrap16(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5422) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.IllegalArgumentException: File app_31/public contains a path separator at android.app.ContextImpl.makeFilename(ContextImpl.java:1944) at android.app.ContextImpl.getDir(ContextImpl.java:1759) at android.content.ContextWrapper.getDir(ContextWrapper.java:258) at com.sromku.simple.storage.InternalStorage.buildPath(InternalStorage.java:152) at com.sromku.simple.storage.AbstractDiskStorage.createFile(AbstractDiskStorage.java:114) at com.sromku.simple.storage.InternalStorage.createFile(InternalStorage.java:18) at com.sromku.simple.storage.AbstractDiskStorage.createFile(AbstractDiskStorage.java:139) at com.sromku.simple.storage.InternalStorage.createFile(InternalStorage.java:18) at net.gazeapp.utilities.MediaTools.copyFileToPrivateStorage(MediaTools.java:80) at net.gazeapp.AddContactActivity.onActivityResult(AddContactActivity.java:225) at android.app.Activity.dispatchActivityResult(Activity.java:6456) at android.app.ActivityThread.deliverResults(ActivityThread.java:3695) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)  at android.app.ActivityThread.-wrap16(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5422)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

Any suggestions how to get this to work?

Found UX bug in create pin screen.

In create pin screen, it asks user to create PIN for the first time. As this is the first time, there is no need to show the forgot password screen. Kindly fix it.

Crash when bitmap pass for create file

java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.IllegalStateException: Can't compress a recycled bitmap
at android.graphics.Bitmap.checkRecycled(Bitmap.java:400)
at android.graphics.Bitmap.compress(Bitmap.java:1307)
at com.sromku.simple.storage.AbstractDiskStorage.createFile(AbstractDiskStorage.java:137)
at com.sromku.simple.storage.ExternalStorage.createFile(ExternalStorage.java:17)

IllegalBlockSizeException

Failed to encrypt/descrypt
javax.crypto.IllegalBlockSizeException: error:1e00007b:Cipher functions:OPENSSL_internal:WRONG_FINAL_BLOCK_LENGTH

Fail to get the original file after encrypting it and decrypting

I am trying to read the database file from a specified app, encrypt it, and save it to external SD CARD.
When I try to get it back, the file contents are not the same.

 //Get databaseFile uncrypted
 byte[] originalDbBytes = storage.readFile("database/path");
 
 //This file is ok
 storage.createFile("path/original/file", originalDbBytes);

 //Add encryption for testing purpose only
 String IVX = "abcdefghijklmnop"; // 16 lenght - not secret
 String SECRET_KEY = "secret1234567890"; // 16 lenght - secret
 byte[] SALT = "0000111100001111".getBytes(); // random 16 bytes array
 EncryptConfiguration configuration = new EncryptConfiguration.Builder()
 .setEncryptContent(IVX, SECRET_KEY, SALT)
 .build();

 //Configure the encription on storage instance
 storage.setEncryptConfiguration(configuration);

 //Create encrypted file.
 storage.createFile("path/encrypted/file", originalDbBytes);

 //Read encripted file.
 byte[] bytes = storage.readFile("path/encrypted/file");

 //Write decrypted file-
 storage.createFile("path/decrypted/file", bytes);

 decrypted file is invalid

Any hints on this? Should this work only with textfiles?

Context is not necessary when only using ExternalStorage

I used this library v1.2.1 in my App Pure Writer. It is great!

I turn to v2.1.0 today, and I found Context is not necessary when only using Storage.getExternalStorageDirectory(). It may be better and convenient that move the Context parameter to getInternalFilesDirectory() and getInternalCacheDirectory() which truly need the Context, and supply a Storage() constructor. How about it?

Thanks!

java.lang.RuntimeException: Failed to encrypt/descrypt

Hi,

i'm having this error when trying to use encryption, do you have an idea ?

02-11 10:04:41.698: E/AndroidRuntime(9964): FATAL EXCEPTION: main
02-11 10:04:41.698: E/AndroidRuntime(9964): Process: com.preiss.swapps.launcherwear, PID: 9964
02-11 10:04:41.698: E/AndroidRuntime(9964): java.lang.RuntimeException: Failed to encrypt/descrypt
02-11 10:04:41.698: E/AndroidRuntime(9964): at com.sromku.simple.storage.security.SecurityUtil.encrypt(SecurityUtil.java:79)
02-11 10:04:41.698: E/AndroidRuntime(9964): at com.sromku.simple.storage.AbstractDiskStorage.encrypt(AbstractDiskStorage.java:411)
02-11 10:04:41.698: E/AndroidRuntime(9964): at com.sromku.simple.storage.AbstractDiskStorage.readFile(AbstractDiskStorage.java:386)
02-11 10:04:41.698: E/AndroidRuntime(9964): at com.sromku.simple.storage.AbstractDiskStorage.readFile(AbstractDiskStorage.java:161)
02-11 10:04:41.698: E/AndroidRuntime(9964): at com.sromku.simple.storage.ExternalStorage.readFile(ExternalStorage.java:1)
02-11 10:04:41.698: E/AndroidRuntime(9964): at com.sromku.simple.storage.AbstractDiskStorage.readTextFile(AbstractDiskStorage.java:169)
02-11 10:04:41.698: E/AndroidRuntime(9964): at com.sromku.simple.storage.ExternalStorage.readTextFile(ExternalStorage.java:1)

Callbacks

Hello,

How do I listen for a success or error on file creation?

isDirectoryExists() always returns true

The result of calling the isDirectoryExists() method on an instance of the internal storage is always true.

Easily checked by writing an androidTest:

@Before
public void setup() {
    Context context = InstrumentationRegistry.getTargetContext();
    storage = SimpleStorage.getInternalStorage(context);
}

@Test
public void shouldCreateTypedFolder() {
    storage.deleteDirectory("sub-" + Type.ONE);
    storage.deleteDirectory("sub-" + Type.ALL);

    // below fails
    assertFalse(storage.isDirectoryExists("sub-" + Type.ALL));

Get Public Directories in External Storage

I think it's a good day give a way to get public directories ( Pictures, Download..) in External storage.

Something like this

SimpleStorage.getExternalStorage(Environment.DIRECTORY_PICTURES)

IllegalBlockSizeException when attempting to encrypt multiple files in a loop

I am trying to encrypt multiple .txt files which will be encrypted over a for-loop iteration. The list of files are stored in a String[] array. The individual .txt files are able to be encrypted without the loop iteration, and the error occurs when attempting to encrypt multiple files. Here is a snippet of my code:

                String[] filenames = getFilenames(selectedFiles);

                for(int fileNum = 0; fileNum<filenames.length;fileNum++){

                    //Read currently working text file
                    String content = storage.readTextFile(extPath+"/"+storedName+"/"+filenames[fileNum]+".txt");
                    System.out.println(" READING FILE FROM ["+fileNum+"] : "+extPath+"/"+storedName+"/"+filenames[fileNum]);

                    //Encrypt file
                    storage.setEncryptConfiguration(configuration);
                    storage.createFile(extPath+"/"+storedName+"/"+filenames[fileNum], content);

                    System.out.println("INFO : FILE ENCRYPTED");


                }

The first file in the Array filenames will be encrypted, but fails upon hitting the 2nd file.

Just my guess, but could it have something to do with the the buffer not flushing?

Bug: Can't create file on ExternalStorage

 java.lang.RuntimeException: Failed to create
                                                                         at 
com.sromku.simple.storage.AbstractDiskStorage.createFile(AbstractDiskStorage.java:129)
                                                                         at 
com.sromku.simple.storage.ExternalStorage.createFile(ExternalStorage.java:17)
                                                                         at 
com.sromku.simple.storage.AbstractDiskStorage.createFile(AbstractDiskStorage.java:104)
                                                                         at 
com.sromku.simple.storage.ExternalStorage.createFile(ExternalStorage.java:17)
                                                                         at 
com.stefanionescu.propi.EditActivity.update_file(EditActivity.java:761)
                                                                         at 
com.stefanionescu.propi.EditActivity.onClick(EditActivity.java:537)
                                                                         at android.view.View.performClick(View.java:5697)
                                                                         at android.view.View$PerformClick.run(View.java:22526)
                                                                         at android.os.Handler.handleCallback(Handler.java:739)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                         at android.os.Looper.loop(Looper.java:158)
                                                                         at 
android.app.ActivityThread.main(ActivityThread.java:7224)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                         at 
 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                      Caused by: java.io.FileNotFoundException: /storage/emulated/0/.secure/info.txt: open failed: ENOENT (No such file or directory)
                                                                         at libcore.io.IoBridge.open(IoBridge.java:452)
                                                                         at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
                                                                         at java.io.FileOutputStream.<init>(FileOutputStream.java:72)
                                                                         at 
com.sromku.simple.storage.AbstractDiskStorage.createFile(AbstractDiskStorage.java:116)
                                                                         at 
com.sromku.simple.storage.ExternalStorage.createFile(ExternalStorage.java:17) 
                                                                         at 
com.sromku.simple.storage.AbstractDiskStorage.createFile(AbstractDiskStorage.java:104) 
                                                                         at 
com.sromku.simple.storage.ExternalStorage.createFile(ExternalStorage.java:17) 
                                                                         at 
com.stefanionescu.propi.EditActivity.update_file(EditActivity.java:761) 
                                                                         at 
 com.stefanionescu.propi.EditActivity.onClick(EditActivity.java:537) 
                                                                         at android.view.View.performClick(View.java:5697) 
                                                                         at android.view.View$PerformClick.run(View.java:22526) 
                                                                         at android.os.Handler.handleCallback(Handler.java:739) 
                                                                         at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                         at android.os.Looper.loop(Looper.java:158) 
                                                                         at 
android.app.ActivityThread.main(ActivityThread.java:7224) 
                                                                         at java.lang.reflect.Method.invoke(Native Method) 
                                                                         at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                                         at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
                                                                      Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
                                                                         at libcore.io.Posix.open(Native Method)
                                                                         at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
                                                                         at libcore.io.IoBridge.open(IoBridge.java:438)
                                                                         at java.io.FileOutputStream.<init>(FileOutputStream.java:87) 
                                                                         at java.io.FileOutputStream.<init>(FileOutputStream.java:72) 
                                                                         at 
com.sromku.simple.storage.AbstractDiskStorage.createFile(AbstractDiskStorage.java:116) 
                                                                         at 
com.sromku.simple.storage.ExternalStorage.createFile(ExternalStorage.java:17) 
                                                                         at 
com.sromku.simple.storage.AbstractDiskStorage.createFile(AbstractDiskStorage.java:104) 
                                                                         at 
com.sromku.simple.storage.ExternalStorage.createFile(ExternalStorage.java:17) 
                                                                         at 
com.stefanionescu.propi.EditActivity.update_file(EditActivity.java:761) 
                                                                         at 
com.stefanionescu.propi.EditActivity.onClick(EditActivity.java:537) 
                                                                         at android.view.View.performClick(View.java:5697) 
                                                                         at android.view.View$PerformClick.run(View.java:22526) 
                                                                         at android.os.Handler.handleCallback(Handler.java:739) 
                                                                         at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                         at android.os.Looper.loop(Looper.java:158) 
                                                                         at 
android.app.ActivityThread.main(ActivityThread.java:7224) 
                                                                         at java.lang.reflect.Method.invoke(Native Method) 
                                                                         at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                                         at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

I can't create a text file in the external storage. Can you kindly help with this?

Initialization blocks main thread with a ~3600 ms init time

Having an issue I am trying to lazy load in Simple Storage but it seems to throw a fit when i initialize on another thread.

Is there a way to asynchronously load simple storage, and do I have set an encryption configuration everytime on app startup?

Unable to delete folder

My folder path is /storage/emulated/0/com.example.demoapp

but i am unable to delete it using storage.deleteDirectory(path);

Can anyone plzz help me in this ???

Encryption key changes after every new app start

Hi,

I just tried your library and found the interface clean and intuitive. However I also wanted to encrypt my data and thus providing an ivx and secret key. I created and loaded data and closed the app. After reopening the app crashed due to BadPaddingException when decrypting the files. I digged a little into your application and found that the secret key keeps changing whenever I restart the app. I think this is due to the salt you add to the secret key. This seems to be broken. Maybe you should have a look into that.

Best regards
dasheck

rename file

is there a method to rename files? Regards.

Decrypt file to its previous condition

Hey, I used your library for decrypting a .jpg image which it successfully did. Now I want to decrypt it back so that I can access it easily(So that I don't have to use library to access data). How can I do that?

Caused by: java.lang.IllegalArgumentException

I got following issue when i try to create directry and subdirectry with . extension like this .MainDirectry/.Subdirectry
Caused by: java.lang.IllegalArgumentException File app .MainDirectry/.Subdirectry contains a path separator
at com.sromku.simple.storage.InternalStorage.createDirectory(InternalStorage.java:41)

Need API to add encryption to already created files

Thanks a lot for your work. There are some cases where the file can be created by external sources like DownloadManager and since android-storage handles encryption/decryption for files only created via its own API.

So, it would be helpful to have an API method, which will encrypt an already present file. Let me know your thoughts!

Can't copy in /system folder

I use the command storage.copy(file, "/system/media/", "bootanimation.zip"); but the app crash because it wants to copy the file in /storage/emulated/0/system/media/ and not in /system/media/. How i can fix it?

Persist data after app uninstall - getExternalStoragePublicDirectory

Correct me if I'm wrong, but this lib doesn't support writing to the public external storage?
So when the app is uninstalled, all data is deleted. It would be good to be able to chose between private and public external storage.

EDIT: I'm reading the docs here. They don't even mention 'getExternalStorageDirectory()'. But now I understand that this latter method does not delete data after app uninstall. Am I correct?

Save Serializable object

I know Serializable is not recommended in Android (should use Parcel instead), but in some situations, I want to save and read back a Serializable object.

Have you ever thought about such methods like storage.saveSerObject(object, name) and storage.readSerObject(name)?

I know with storage.createFile("MyDirName", "fileName", "some content of the file") and storage.readFile we can be easily create such methods for Serializable object, however I still would like to have them built-in.

External SD Card

Hi

just saw your nice project and made some test. It is only possible to access the app directory and external storage on the internal sd storage (memory)

But it is not possible to access removable media like an external storage sd card ?

I think this is only possible with Scoped Directory Access ? I tried to figure this out but i do not have a real solution yet.

maybe you could add these features to access removable storage too ? its possible since api 24 i guess

greets

frank

SAF (DocumentFile) support

I looked through your code, I did not find any handling of DocumentFile and any SAF (storage access framework) usage. Am I right, that you're not supporting external storages on android >= 5 (sd cards for example)?

Any plans on adding this?

jcenter() error

jcenter() is deprecated. Please update jcenter() to mavenCentral()

BUG: OrderType's comparators are wrong

OrderTypes are used for Collections.sort(list, comparator), but they are wrong, will lead to sorting error:

https://github.com/snatik/android-storage/blob/422a2b9cda205f8aa630d1c2604e1dafbc4897d3/storage/src/main/java/com/snatik/storage/helpers/OrderType.java#L27-L33

https://github.com/snatik/android-storage/blob/422a2b9cda205f8aa630d1c2604e1dafbc4897d3/storage/src/main/java/com/snatik/storage/helpers/OrderType.java#L34-L40

Try the test code:

TextView textView = findViewById(R.id.text);

ArrayList<Long> list1 = new ArrayList<>();
list1.add(1507755342589L);
list1.add(1507531570030L);
list1.add(1507403960822L);
list1.add(1507321017313L);
list1.add(1507235255461L);
list1.add(1507019735509L);
list1.add(1506985739800L);
list1.add(1510980593823L);
list1.add(1510884152730L);
list1.add(1510800393165L);
list1.add(1510372364493L);
list1.add(1510303509229L);
list1.add(1510293661701L);
list1.add(1510252260159L);
list1.add(1510179005397L);
list1.add(1510175799845L);
list1.add(1510095195735L);
list1.add(1510033172644L);
list1.add(1509974318427L);
list1.add(1509943757032L);
list1.add(1509906830316L);
list1.add(1509831147380L);
list1.add(1509812300328L);
list1.add(1509727408576L);
list1.add(1509659137459L);
list1.add(1509643466555L);
list1.add(1509597096744L);
list1.add(1509589493932L);
list1.add(1509501326282L);
list1.add(1509388926800L);
list1.add(1509360302279L);
list1.add(1509356734439L);
list1.add(1509249505561L);
list1.add(1509231210646L);
list1.add(1509228906474L);
list1.add(1509178702873L);
list1.add(1509119878492L);
list1.add(1509082817356L);
list1.add(1509042775375L);
list1.add(1508993607081L);
list1.add(1508990994790L);
list1.add(1508828403615L);
list1.add(1508762233971L);
list1.add(1508760776821L);
list1.add(1508727292580L);
list1.add(1508652546740L);
list1.add(1508633168391L);
list1.add(1508630744611L);
list1.add(1508500074390L);
list1.add(1508450769498L);
list1.add(1508444644300L);
list1.add(1508437127306L);
list1.add(1508419676999L);
list1.add(1508285637664L);
list1.add(1508273536784L);
list1.add(1508252239396L);
list1.add(1508241963462L);
list1.add(1508168648223L);
list1.add(1508160093931L);
list1.add(1508157246670L);
list1.add(1508135118936L);
list1.add(1507993768247L);
list1.add(1507958838417L);
list1.add(1507921437341L);
list1.add(1507899425055L);
list1.add(1507893347971L);
list1.add(1507855048760L);
list1.add(1507842285948L);
list1.add(1507834395876L);
list1.add(1507781709865L);
list1.add(1507764701974L);
list1.add(1507722142629L);
list1.add(1507648765778L);
list1.add(1507639201021L);
list1.add(1507607547432L);
list1.add(1507582839677L);
list1.add(1507539374452L);
list1.add(1507419694994L);
list1.add(1507398327485L);
list1.add(1507339481930L);
list1.add(1507337813397L);
list1.add(1507317123522L);
list1.add(1507291990718L);
list1.add(1507178591427L);
list1.add(1507162863060L);
list1.add(1507143200015L);
list1.add(1507093413099L);
list1.add(1507031582973L);
list1.add(1506987003095L);
list1.add(1506962797059L);
list1.add(1506774676535L);
list1.add(1511044834901L);
list1.add(1510904955797L);
list1.add(1510883452075L);
list1.add(1510790200105L);
list1.add(1510747571715L);
list1.add(1510662308710L);
list1.add(1510542646559L);
list1.add(1510257559848L);
list1.add(1510037484253L);

ArrayList<Long> list2 = new ArrayList<>(list1);
textView.append("before: " + (list1.equals(list2) + "\n"));

Collections.sort(list1, new Comparator<Long>() {
    @Override
    public int compare(Long o1, Long o2) {
        return (int) (o2 - o1);
    }
});
Collections.sort(list2, new Comparator<Long>() {
    @Override
    public int compare(Long o1, Long o2) {
        return Long.compare(o2, o1);
    }
});
textView.append("after: " + (list1.equals(list2) + "\n"));

The result is:

before: true
after: false

So the correct way should be like Long.compare (x, y) or Integer.compare(x, y):

return (x < y) ? -1 : ((x == y) ? 0 : 1);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.