I'm geting a file from server, and storing it on the phone. It's a PDF. Then I need to display . Assuming that I have a PDF viewer it will open the file.
The question is where should I store the PDF file so my pdf reader has access to it. I don't really want use external storage since not all phones has one. Is there a way to save public file on internal storage?
Or there is some way to pass the necessary information using ContentProvider. Unfortunately I would need some sample code of that.
All you put under internal directory can't be access by other applications. so getDir or getCacheDir have to be used only for your application.
If you need files to be open by other application you have to write files under SD card.
Related
I am generating a file in a .NET MAUI application, and I want to save it to the Files folder. I followed the issue asking about how to save a temporary file in .NET MAUI, but I want my output to be "permanent" location (well, until the user deletes it, anyway).
I am using the following code:
string FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "myfile.gz");
byte[] arr = GetDataToSave();
await File.WriteAllBytesAsync(fileName, arr);
I'm running this code on an Android emulator, and I'm expecting to see a file created here:
I'm looking for the file so I can drag it to my Windows machine and inspect the contents to make sure I created the file successfully. But, it's not showing up.
How can I save a file from .NET Maui in such a way that I can see it in Files on the Android Emulator?
From the following code , we can find that you are trying to save file to internal storage.
string FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "myfile.gz");
And from document File Storage and Access with Xamarin.Android, we know that
Internal Storage – this is a portion of the file system that can be
accessed only by the application or the operating system.
So, if you save file to internal storage, you cannot access this file by other apps. That's why you can't see this file with other apps.
Of course, if you want to see this file with other app, you can save your file to External Storage.
External Storage is a partition for the storage of files that is accessible by all apps, the user, and possibly other devices. On some devices, external storage may be removable (such as an SD card).
For more details, you can check document: External storage.
And there is also an sample included in above document, you can check it here: LocalFiles.
I am developing an app in android where it download image files and use it as app resource. I want to save the file in a directory so that user can't see this as media files shown in gallery. I just need to know the specific directory where i can save the file and the user wouldn't able to see it.
Android would automatically scan all folders on external storage for media files. If you don't want your image files to show in the gallery, maybe you could add some extension like ".myapp", this way cheats the scanner.
Using the Internal Storage You can save files directly on the device's internal storage. By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). When the user uninstalls your application, these files are removed.
Just Simple apply your own logic.
when u read the file from internet is byte format.
and after right in to sdcard.
this time just change the some byte of read file.and store this byte in some place like a sharepreference,Static varibale anything.and when you read file and display else play then change the same byte agian and replace this byte with orignal.this call incrypt and decrept.
it`s work dear i do for image file.
Just add a file named .nomedia in the directory you want to exclude from MediaScanner.
Another alternative is to save your image in a Database as a BLOB.
With this you are 100% sure that only your application can access it.
I have a document file stored in my application's data folder, which is a kind of private folder to the application. It is a .doc file. I have doc viewer application installed in the device. Now, how can I open the file with the Action_view intent. As the viewer application can't access file stored in my application data folder, it is throwing an error saying file can't be accessed. I have no interest to copy the file to phone public folders like sdcard. Is there anyway to open that doc file. Any clue on embeded apk in android.
Thanks & regards,
Suman
You can't do this directly. Either copy the file temporarily to the SD card (external storage) or set permission temporarily to WORLD_READABLE. There are no embedded APKs in Android, but if the viewer is available as library you can include it in your app. Of course the problem with changing permissions temporarily is that you don't really get notified when the user has finished viewing it, etc.
The whole thing begs the question: why is it a private file if it needs to be viewed by third party applications? If it is meant for the user of the device, there is not much point in hiding it from them...
I am developing an android application and i need to read words from a file to create a Trie. Is there a way i can write the file to internal storage on install so that only my application can access it, or should i hard code the words. Any suggestions are appreciated
If the file isn't going to change, you should put it in your assets directory. If it is going to change, you can copy it from your assets to internal storage and it'll be private. External storage (often an SD card) is word-readable.
http://developer.android.com/guide/topics/data/data-storage.html
http://developer.android.com/reference/android/content/res/AssetManager.html
Can anyone help me ? Is it possible to create shared preference files in sdcard rather than on private path of an android application.
You cannot modify where shared preferences are stored.Its a private storage. if you want to use sd card use
Environment.getExternalStorageDirectory(). and get the path of directories stored in sdcard.
it is possible by reading&writing the xml file into the external storage ,but it's not the same as sharedPreferences. you will have to implement your own way , or use the android code of this class.
however , there are some disadvantage over using the internal storage:
anything you store on the sdcard is visible to every application and the end user can read it by just opening it.
only in the internal storage you get some sort of protection against reading the file , so that only rooted devices can read the files.
external storage can also be unmounted , so the data can sometimes be unreachable. you need to handle possible errors that can occur because of this.
uninstalling the app while the sd card is mounted means that the data will stay on the sdcard .