I want to use skyEpub SDK in my Android application to show my Epubs.
I'm Encrypting my epub files in SDCard and never want to extract them in any physical place (because of security reasons)
I know how to read and decrypt my file into a byte array. But My problem is that I don't know how to send it to the sdk. I've traced the sample project and found that it extracts the epub file into a directory and then use it , but I don't want to extract raw files in sdcard ever!
I founded that I should implement ContentListener and do something in it but don't know what exactly should do.
Related
Existing Xamarin Forms app on Android.
New feature request from the bosses: To copy some updated documents from a USB FlashDrive to a known directory on the extSD already in the tablet.
Seems like that shouldn't require a PhD. Everything we've done to date has been on the internal storage so typical System.IO calls work fine. But Android has this whole Storage Access Framework stuff in place for things like the external SD, or Google Drive or where ever.
Every question and tutorial I see are all for the same thing: How to open a document browser to the SD card, or how to create a new CREATE DOCUMENT INTENT.
I'm not looking to do any of that. Don't need a UI. Not making a new text file from scratch.
I just want to copy a file from the flashdrive to the extSD. Everything else is in place to do this to internal storage. Easy-Peezy.
Its a single line when copying from the flashdrive to the internal SD.
FileInfo.CopyTo(targetAddress, true);
How do I copy a file to the extSD? Do I really need 200 lines of overhead making a DOCUMENTPROVIDER, and CONTRACT and 20 other things just to copy a file? All I get is "ACCESS TO extSD 1234-5678 is denied". Seems like it should be fairly simple to get permission to the card then just copy a file or make a new folder. But I swear everything I read for SAF makes it sound like you have to make 10 classes and a manager for them all first.
Anyone got a simple example of the minimalist way to get write permission to the extSD and copy from A to B?
If it is copying only one file them its pretty simple. Let the user select the fle with ACTION_OPEN_DOCUMENT. You get an uri for the file. Now let the user create a file at the right place using ACTION_CREATE_DOCUMENT. You got another uri. Now open an InputStream and an OutputStream for those uries. Then read bytes from input and write to output. Less then 200 lines ;-)
I have an application that I want to develop. The android application is more or less like a book that will allow the users to select a chapter and it will display the whole text in that chapter and a media file for the chapter. Where do you think I can store the text and the media. Should I use json format or sqlite database or I should store both text and media in a folder and access it there. Am really confused because I still want to be able to perform some query on the text search for the text in my application.
You can use binary files, where you load the data sequencial.
Or you use zip-files, in which format many programs store data. Eg .svgz is a zipped version of .svg used by Inkscape, .odf is an open source format used by eg. OpenOffice or LibreOffice (the specification says it could be either a XML- or ZIP-structure.) You can store the text in a file, where in the text it references to other files like images in the zip, like a html-file references to other files on the server in the directory. This can be a json-file or an xml-document or a binary-serialization of an object-structure. There are many zip-libraries out there,. It is a big security risk, if you do not check in the file for references to other files outside the zip, like '../../Documents/myPasswords.txt' (when you are on Windows for example and you use the %temp% directory, this may reference to 'C:/Users/BOB/Documents/myPasswords.txt' when the directory where you unpack to is '%temp%/randomName/'), when unpacking the data to a temporary directory and load a file (however different operating systems treat this differently, Android is more secure than Windows, but the app can crash if you do not check...).
But if you do not care about filesize and if you store the data directly within the app (and not download them from the internet), you just include it in your data-folders.
I have code for creating an internal file, there is random algorithem that create the data stored in it and i want any app to have the same file with the same binary data in it.
so i need to make the file on my desktop and add it to internal files some how.
my question is what do you think is the best way to do it.
i thought to locate it in my project, read it, and write it to internal files.
the problem is, i dont know where to locate my file in android studio so that it will be included in the external files and then where to read it from.
thanks. =]
hope i made myself clear.
Put it in src/main/assets/.
You can then access your file with AssetManager and do whatever you want with it.
From the Android Developers website:
main/assets/
This is empty. You can use it to store raw asset files. Files that you
save here are compiled into an .apk file as-is, and the original
filename is preserved. You can navigate this directory in the same way
as a typical file system using URIs and read files as a stream of
bytes using the AssetManager. For example, this is a good location for
textures and game data.
You need to move that into the assets folder. From there you can refer to the file.
So I have some files I want my Android App to access, read and write.
I want to store it internally. Where can I put these files in my Java Project so they are accessible or can this not be done?
There are three ways to achieve this, and according to your requirements select the approch
on SDCARD
This is the normal SDCARD/in-build SDCARD in newer smart phones. you need to create specific folder structure and put your files there, here you can do file read and write both
but this in insecure because accessible to all the application
on Internal Storage
This is given as Applicaiton specific storage where you can create the file and do the operation, this is most secure way to do it, but this is generated run time so you can not push the files directly, you can put your files in RAW or ASSETS and copy that here
RAW and ASSETS
This is in the code structure only and only read access is given to this folder, you can not change this file run time.
if you select any one of this approach then simple goggling will show you the sample code.
You can read or write files in the path of your internal storage as
data/data/package_name/files . I had already answered a similar question you can check it out.
In my application I need to pass a dynamically decrypted file to a third-party application without saving it to the device.
Example: I have a self created encrypted file which contains both a pdf file and some requirements before the pdf file can be shown. If all requirements are true, that pdf file should be shown by a third-party PDF-reader.
So I need to start a new intent, but there is the problem. I have to give the URI of my pdf file, but I don't have a URI because I didn't save the file to the device.
Is there any way I can get this job done?
For very small PDFs, or PDFs encrypted with some sort of streaming encryption algorithm, you can create a pipe ContentProvider. Using a pipe, you basically pour data into an OutputStream, where the other side uses a Uri and ContentResolver to retrieve the corresponding InputStream.
However, the limits of heap space will severely constrain the size of the file, if you cannot process it in a streaming fashion (e.g., as you read the bytes in from HTTP, decrypt on the fly and pass the decrypted bytes to the OutputStream).
Here is a sample of creating such a ContentProvder.
Answer on my own question:
Together with the answer from CommensWare (and sample code) and this link I have found a semi-solution.
The sample code shows you how to make local files accessible for other applications with a content provider.
The second link describes the implementation of a delete method which deletes the file from the file structure even before it is completely opened by a third party application (and explains why this is possible).
So basically, after decryption, you create a file accessible from the content provider, open it with another application and delete it immediately.
For rooted phones this is still not a 100% solution because they could monitor local file structure changes and instantly copy the file after it has been created.