i'm making a hand-outs reader, i have an xml file contains the file link and the file thumbnail, i managed to parse the data inside the xml and save it in the sdcard.
having a /mnt/sdcard/App/File directory for the downloaded files(.pdf, .ppt files) and /mnt/sdcard/App/Thumbnail for the downloaded thumbnails(.png, .jpeg/.jpg files)
i want to reference the image to the downloaded file (like when i click the image the file will show or open the referenced file) is it possible? if yes how can i do that?
This tutorial should get you started on how to read/write from the SD card (if you don't already know how to do so), and this tutorial should show you how to retrieve and display images stored on the SD card.
Related
In my flutter project, I want to download some files from a url and save particularly in a folder named data. I have added Read and Write permission in AndroidManifest.xml file. I have also tried some solutions like the below link-
flutter - How to download asset when apps launched and used it
But none of them was effective for me. some of the solutions let me save the file in SD card but I only need to save the file in my data folder and read data from the file whenever I need.
Here's the picture where I exactly want to save my file-
So, I need a proper solution to download the file from the url and save it to this particular directory.
https://pub.dev/packages/download_assets if you don't want to add assets at time of build try this package it download asset from server and store it in assets
This is a real newbie question.
I am going to be creating an app that downloads an XML file, which contains links to mp3 files.
Where should I download these files too?
I mean can I bundle the XML file under /res and then download the latest XML file over the top of it? Currently I have some mp3 files in /res/raw.
Would I be able to do the same?
I think you should save your XML file in your own directory in SD Card and just read that file content using XmlPullParser in your application.
File file = new File(Environment.getExternalStorageDirectory() + "/your_dir/your_xml.xml");
How to create Folder/Directory in SD card ?
How to read XML data from SD Card ?
I hope this is enough as per your requirement.
What I'm trying to do is put a file in the app (Like in assets or resource).
But I need to load it by its path "I don't want to use the assets manager .. etc", this is because I'm using a lib need the file name (Not stream).
Note1: I know I can save the file to SD card then use it, but I'm trying to find a way without doing this (Load it directly).
Note2: I tried "file:///android_assets" but it didn't work.
You cannot access asset files via File API because it stays in your APK, which is in fact just ZIP file. Files in asset folder are accessed through native asset API where it is handled as ZIP stream. You can see Asset.cpp and its method createFromCompressedFile.
In my application, I have created a bitmap and save it as a JPG image in the SD card. I don't want any other apps to use this image. Is this possible in android ? Any help will be greatly appreciated .
Unless you encrypt the file, there is nothing you can do to prevent access to files on the SD card.
(See the section on external storage here)
Files saved to the external storage are world-readable and can be
modified by the user when they enable USB mass storage to transfer
files on a computer.
Instead consider putting it in internal storage, then your application will be the only one that can access it.
Another option, if you only need to hide it from media scanners is to either give it a name that starts with a dot (.myfile.jpg) this will make it a hidden file. (if you have multiple files you want to hide this way, include an empty file with the name .nomedia (see Saving files that should be shared) so you don't have to rename them all)
When storing the image, change the extension of the file to something else, so other apps would not recognize it. But when you want to use it in your app, change the extension back to .bmp or .jpg!
Use an application specific database and save your images there instead saving it on the SD-Card. Then only your application has access. I'm doing this to encrypt the images in my application, just saving a BASE64 encoded image string doing crypto stuf on it and vice versa. This would also work if you save a Byte Array of the image file.
Method 1 – Creating A .nomedia File .
Using any file explorer/manager application (such as Astro File Manager or File Expert), navigate to the directory that you want hidden and create an empty file titled “.nomedia”.One way to do so is to:
Copy an existing text (.txt) or even an image (.jpg/.jpg) file to said directory,
Open it in a text editor (hold down on the file and select the appropriate option from the context menu that appears),
Delete its contents (hold down on the text, Select all and Delete), save changes and exit,
Rename it to “.nomedia” (hold down on the file again and select Rename from its context menu).
This method disables media scanning on the chosen directory, causing the Gallery to skip the directory altogether at launch.
In my application i need to open pdf file.For that i have prepared code to open pdf file.Suppose my pdf file in sdcard, It is working fine.when my application change from sdcard to application path i.e /data/data/app.package/ it is not working.I got alert dialog like
Invalid file path .Please guide me to over some this problem.
/data/data/app.package/ is package private. To share this pdf you'd probably have to move it to external storage (you can use getExternalFilesDir()). This directory has no security enforced.
You must make /data/data/app.package/file.pdf redable for other applications.
1) using openFileOutput(fname, Context.MODE_WORLD_READABLE).close(); create share file in your app data directory.
2) write pdf file to created file using Streams (you may write to stream returnet by openFileOutput instead of close it)
3) open your pdf file