I'm creating an Android app that needs to download a set of images and audio files in order to work properly. Those files will be updated on the server from time to time. On startup, the app will check for updated files and download them.
My concern: The updates/downloads of those files must be completed in an atomic fashion, meaning that the update is successful only if all files have been downloaded. If one file failed to download (reason being poor internet connection, insufficient storage space on the phone, etc), the update should be rolled back.
I feel that implementing something like that from scratch could be a pretty big task, so I first wanted to ask if there's already a library/module, or at least a best practice for implementing something like this.
I feel that implementing something like that from scratch could be a pretty big task.
I disagree:
Your app can creat a temporary private folder (i.e. -tmp-update-20190321_122800) and download all files into this folder.
After all downlads finished without error the app can replace the original files.
So instead of searching for a transaction-multi-filie-download-lib you can use any android-download-lib and you must know how to copy/move/delete files.
Related
I have an app that wants to have the ability to download files locally. A user can download a file (no restrictions to file type) and should be able to save it on the device so it can be used for other purposes. I would also like the user to be able to delete the file from the app (they would know which file is downloaded and which isn't, a ticker would indicate if it's backed up locally). Say it is a pdf file -- the user would want to open it with different apps or edit it if they have the ability to, or just share it via email. Considering we cannot opt out of scoped storage anymore (requirement to target 30), I got a couple of questions.
I've tried to use Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()) and also getExternalFilesDirPath(ctx, Environment.DIRECTORY_DOWNLOADS)). While the former is deprecated, it works for me in that the Files app can be used to navigate to the file in question (and possibly open/delete the file). On the other hand, I am not being able to delete this file from my app due to lack of permissions. Obviously, the latter path is unable to be navigated to by another app (or is it? I haven't found a way, hence the question).
The other thing I've considered using is the MediaStore API but I'm struggling to see how this is an improvement over the old ways in terms of function. Disregarding moving back to manual content resolver and cursor usage, how should arbitrary files be sorted? Should I manually sort by mime types and have different methods for saving for specific media types? It sounds exceptionally tedious and counter intuitive. If this is the way, so be it, I will implement it, but it does not sound like the way to go. On the positive side, it at least sounds like a solution due to the content resolver's CRUD abilities.
I'm working on a RN app that uses a 3rd party library for the download paths, which old/new versions, respectively, use different paths (rn fetch blob and rn fetch blob util). Additionally, MediaStore API doesn't have a RN implementation as of right now, so everything would have to be done from scratch, too.
What are my options? In the short term I'm considering disabling the erase feature from the app (at least for now). Anything I am missing and should consider? Thanks in advance.
I'm not sure if this is the right place to ask this question but I've looked around and couldn't find the answer.
An app that I'm building allows the user to download files, but I want to protect the URL of the files.
Is there a way to find the URL of a file being downloaded via an app?
If there is, can I prevent it somehow?
I am using download manager to download the files. Is it any different in this aspect if I write my own async methods?
Similarly, can users see the GET requests sent by the app?
Any info or direction to pages that talk more about this is appreciated.
Thanks.
I am using download manager to download the files. Is it any different in this aspect if I write my own async methods?
If you are using DownloadManager to download files, depending on how you're using it, yes, users could get the URL quite easily, since the downloads app may show it. (this depends on how you're actually doing the download with DownloadManager, I'd need to see your code in order to tell you for sure.
If you write your own code to do the download, then yes, it will be harder for users to figure out where the file is being downloaded from.
Is there a way to find the URL of a file being downloaded via an app?
Even if you don't use DownloadManager, it is still possible, just more difficult. If users are using a firewall which logs network accesses, or something similar, your URLs will be logged and visible. Similarly, users can use a tool like Wireshark to see all networ traffic going between the device (and your app) and the server your data is coming from. On rooted devices, users can also install monitoring tools.
Similarly, can users see the GET requests sent by the app?
Yes, using the same tools (eg. wireshark), one can see exactly what URLs your app is requesting.
If there is, can I prevent it somehow?
No. If someone wants this information, they will get it, all you can do is make it harder. For starters though, I'd recommend not using DownloadManager and writing your own code instead, and using HTTPS. Additionally, you could try to ensure that your URL only works for users which have been authenticated in some way - check this question for possibilities.
Let me know if you have any other questions, and I'll try to help.
I'm developing an app which reads content loaded on my company's server. How can I detect if new files are loaded into the designated folder online or whether any of the existing files has been overwritten in that folder?
From what I've researched so far,
(1) FileObserver seems to be a likely solution, but can it check on a specific URL?
(2) I've used Json's Request.Method.HEAD on a single file to detect updates, but I currently have close to 500 over files (and growing) in that folder and it seems like a potential resource hog to process the header information every time the app loads.
Anyone has suggestion on what functions to use, or library which can help in this scenario?
Many many thanks!
How can I detect if new files are loaded into the designated folder online or whether any of the existing files has been overwritten in that folder?
Have the server notify your app of changes, such as via GCM.
Or, have the server publish some sort of a changelog that you monitor.
FileObserver seems to be a likely solution, but can it check on a specific URL?
FileObserver is for local files.
I've used Json's Request.Method.HEAD on a single file to detect updates, but I currently have close to 500 over files (and growing) in that folder and it seems like a potential resource hog to process the header information every time the app loads.
Agreed. Your problem is on the server. Your server needs to provide the change details in a more efficient fashion.
Create a small API that will have method smth like
List<String url> getAllChangedFiles(long timestamp) that return all files that had been changed from your date. In this case all time consuming logic (like searching for such files) will be on the server, you even could cache it for some reasons.
GCM is not a perfect solution 'cause there is no guarantee that your push notification will be delivered.
I need to develop an offline application in which it has got around 700 images, around 100 videos, 100 pdf's need to be included along with apk.Currently i have put images in drawable folder,videos in raw folder, and pdf in asset folder.When i build the application including all this apk size goes upto 1.5gb.My question is
1.Is it appropriate to include images and video in res folder?Is there any other method to handle this situation
3.One peculiar error will get generated when you build the app that is "package r does not exist android studio".Even though apk gets generated,studio shows this error
It's best to make use of Google Play APK Expansion Library for handling large application data. Imagine having the user download/install a single 1.5GB APK file.
Possible reason: R is re-generated by your environment everytime you add a new resource, as you are using a lot of files this may take time and during the process you will get the error R doesn't exist
Best way would be if you keep the app light without images and videos, only download the files from the server after the user installs the app, on a per need basis. You can save these in the SD card and save users on phone storage space as well.
First of all, if there's gonna be so much data then it should not be in stored in the App (APK). Also google doesn't allow this big APK to be uploaded at once, the big apps are divided into parts. You must have seen for the big games it first downloads a game, it starts and then downloads big amount of data later. But in your case I think the standard way to handle this situation would be to keep all this data on the server and whenever you need it just request it from there.
The best suited for this is to use "facebook conceal"
Im working on a self-test app.
And I wondering on how to store the data, I've got over 200 questions and more is on the way.
Was thinking of storing them as XML but didnt find a way to get a random question without reading the whole string-array to a variable, which is bad for the memory.
So the correct way to go is to use a SQL-database, right?
But how do I make such a database so that it exists at boot and dont need to be made during start up?
Can't seem to find any tutorial on this subject, on how to handle questionnaires.
Here's a good tutorial on SQLite and Content Provider. It'll introduce you to using SQL databases on Android, and wrapping them into a ContentProvider.
As for how to get the data to the device - you have two options:
You pack the SQLite .db file in the application assets folder. Pros: the database is ready for consumption on the first run of the app. Cons: your .apk is too big. Updating is hard.
You download the data on the first run. Pros: your .apk is slim. updating is easy Cons: there's a delay before the user can use the app.
You ship a small .db file with the first 10 questions. Pros: Your users can start using the app immediately, while you download the rest of the questions in the background. Cons: You have to pick 10 questions you're likely to never or rarely change, or you risk your app to start with outdated data.
Create the db offline and either put it in the apk or download it.