1

I am working on an android app where users download files and those files will be encrypted (trying to implement this How to encrypt and decrypt file in Android?) in device. but currently my app does not have file openers to view.

So, I want to let the user choose any file app to open and read using Intent. Since, the file is encrypted, other apps might not be able to open those files. Encryption is to not let users share/show/see the files to anyone without using the our app. Is there anyway to let users use other apps and still encryption in place? Or is it correct way to do it?

Naroju
  • 2,637
  • 4
  • 25
  • 44
  • "I want to let the user choose any file app to open and read using `Intent`" -- what *precisely* do you mean by this? – CommonsWare Aug 07 '21 at 10:52
  • I'm asking the other way round - "where are your encrypted app files stored"? If you use the internal storage then only your app has access to the file for viewing/working/decryption. – Michael Fehr Aug 07 '21 at 12:09
  • @MichaelFehr I save files on the device (internal storage). – Naroju Aug 07 '21 at 19:15
  • @CommonsWare launch an intent something like this https://stackoverflow.com/questions/31621419/android-how-do-i-open-a-file-in-another-app-via-intent – Naroju Aug 07 '21 at 19:16
  • "Encryption is to not let users share/show/see the files to anyone without using the our app" -- this is fairly pointless. If you store the content in `getFilesDir()`, the only way the user can access it is by rooting the device. Many who have the skills to root the device will have the skills to decrypt the content. What you are doing is called DRM, and DRM comes in two forms: the stuff that has been broken and the stuff that nobody has bothered trying to break yet. – CommonsWare Aug 07 '21 at 19:27
  • But, if you insist, you could create a `ContentProvider` that serves the decrypted content, and use a `Uri` pointing to that `ContentProvider` in your `ACTION_VIEW` `Intent`. Or, decrypt the content to `getCacheDir()` and use `FileProvider`, deleting the decrypted content after some period of time. – CommonsWare Aug 07 '21 at 19:29
  • @CommonsWare. I want to create offline experience for my users, at the same time I don't want users to go to internal storage and grab file from app folder. sad part is.. i don't have file viewers in my app. I don't have other chance but to let other apps open our files. What is the best to achieve this? – Naroju Aug 07 '21 at 19:38
  • "I don't want users to go to internal storage and grab file from app folder" -- the only way that users can access what the Android SDK refers to as [internal storage](https://commonsware.com/blog/2019/10/06/storage-situation-internal-storage.html) is if they root their device. "What is the best to achieve this?" -- store your content in what the Android SDK refers to as internal storage (`getFilesDir()` and `getCacheDir()` on `Context`), and use `FileProvider` to make them selectively available to other apps via `ACTION_VIEW`. – CommonsWare Aug 07 '21 at 19:39
  • @CommonsWare, my bad.. I am storing files here `Environment.getExternalStorageDirectory()+'/app_name/'`. due to storage limitations in internal storage. – Naroju Aug 07 '21 at 19:43
  • What limitations are you referring to? Since Android 3.0, internal storage and what the Android SDK refers to as [external storage](https://commonsware.com/blog/2019/10/08/storage-situation-external-storage.html) usually share the same physical "disk" and share the storage. – CommonsWare Aug 07 '21 at 19:46
  • Size limitations, we have like 500MB of files. I think I am confused by the terms "internal storage and external storage". But i understood your point with `ContentProvider`. Thanks – Naroju Aug 07 '21 at 19:55

0 Answers0