Why does android allow delete a file that being used .....? - android

Why does android allow delete a file, although it is being used by another application?
For example: I have a mp3 file on sdcard, I use mp3 player to play it, and then I open a File Manager app and browse to that file; delete it successfully.
If on windows, a message will be displayed and we can't do that.
Why does the android operating system not?
I don't know the principle of file management on android os.
Does anyone have document about it? Help me please!

Going with the information from here (similar query to yours), linux file deletion only removes the pointers to the file until the last process using that file is complete. At this point the contents of the file are freed.
What this means is that the following should not work:
Play an MP3 file from the SDcard.
Open up file manager app and delete said MP3 file.
After MP3 file finishes, attempt to play it again.

Related

How to save and play a video file only through the Application in Android

I want to save a number of video files through the application on the mobile so that the user can not open the saved files and the files can only be run through the program and if the user finds the storage location of the desired file, can not that video file To run. In general, only saved files can be run through the application.
Like the image below, the video file is found but can not be played, this file is opened only by the Application:
Even if we convert this file to video file format, it will still not run
Just store it in your app's file directory. Those are private to your app and cannot be accessed by other apps or by users. It won't prevent a user who has rooted his device, but nothing can really prevent that.

Where is this file located on device?

I'm using the react-native-camera module in order to record video. After it records it gives me the uri of the location of the .mp4 video as:
file:///data/user/0/com.cassette_code/cache/Camera/a608b09c-e572-4056-9927-c0e8988cd254.mp4
I don't know where this is located. I recorded this on an android phone. Could someone tell me where I can access it, or if I can specify the location where the video should be stored in my project directory? I looked through the phone's storage, but I don't see com.cassette_code. I'm running it through my phone using USB debugging, so that might be why. But where would it be?
open your file manager in your android phone then select internal storage then android file then data file and finally select your app file
You may have to install something like ES File Explorer, then find the file using that app. Most built in file browsers can't see the application files

Android : Downloading the HTML file from server and save it into assets folder

I want to host an HTML file on server and once user is registered on the app, i want to get this file downloaded and saved into assets folder of the app on the local device and once i have this file into assets folder, i will display it into a WebView and user should be able to see the contents of that file every time user opens it.
And whenever i update the file on server, i want to display a popup for user to accept it, and once user have accepted it, i want to replace the old HTML file from assets folder with the new one.
And from now onwards, the new file will be downloaded on the local system and every time user wants to access the file, he should be able to access the new one.
I'm not sure if that's possible at all, but would certainly be interested in hearing from anyone that knows anything about such things.
Since I cannot write any files to assets or any raw dir, where it will
be written?
openFileOutput() writes to internal storage.
What will the location of that file be? Where will it be located in
the Android file system ?
The apk is read only and the assets/ folder is not modifiable at
runtime, which sounds like something you may be seeking.
Link Source

Android: Open file extension ONLY with my App

i have an android app, which imports and exports zip files. When exporting, the app creates a zip file with the extension (lets say) .xyz123
Now,when I go to the explorer and click on the file (e.g) text.xyz13 , android offers multiple apps to open my file.
Question: HOW-TO manage, that the file will only be opened by my app ?
thx a lot :)
that the file will only be opened by my app ?
Don't have the file on external storage in the first place.
If the user can get to the file via some sort of "explorer", then the user gets to decide what to do with that file, just as they can on any other operating system.
Moreover, the typical role of "imports and exports" is to allow the user to do whatever they want with the file.

android cannot open downloaded file

I successfully download a pdf file from the internet and then I open the downloads folder using the following Intent:
Intent pdfFileIntent = new Intent();
pdfFileIntent.setAction(DownloadManager.ACTION_VIEW_DOWNLOADS);
ctx.startActivity(pdfFileIntent);
This code is located within the onReceive() method of a BroadcastReceiver I created to deal with download complete events.
The download is complete and successful (I can see the download status in the downloads folder, which is opened right after the download is complete, as expected). However, when I click the newly downloaded file, another dialog pops up which requests me to select the application with which the file will be opened (I can select either Adobe Reader or Quickoffice). When I select Adobe Reader, I get the error : "The document path is not valid" and when I select Quickoffice, I get the error: "File cannot be opened".
This is terribly annoying especially because the downloads folder and the download process and management of downloaded files is completely out of my hands - Android is aware of the files in the downloads directory when it presents them to me, so how can it be that it doesn't pass a valid path? What is going on?
To make things clear, I didn't specify any path in my code - Android chose the path in which to save the file. And I can even see that the file has a reasonable size in KBs, which means it's not empty and it's definitely a pdf file (.pdf extension).
Please help. Thanks in advance.
And I can even see that the file has a reasonable size in KBs, which means it's not empty and it's definitely a pdf file (.pdf extension).
The fact that a file has the PDF extension doesn't necessarily make it a valid PDF file! Move the file to your PC and see whether you can open it there. You may have a bug in the code performing the download, causing some invalid content to be written to the file.

Categories

Resources