Site parsing and opening with slow internet connection - android

I am making a network app that works with a few news sites. I have an option to view and download articles (for reading in future). There is no fast mobile internet in my country (mostly 2G with the speed up to 15 KB/sec) and my app doesn't work really well with the slow connect though it's perfect with fast connection. As I have seen from logs it can't establish the connection. When I try to open the article it doesn't load at all or goes into infinite loading. When I try to save the article it simply saves the blank file. How can I track these mistakes and catch them? And what are the correct ways of handling it?
I suppose that my code is irrelevant as it works correctly with Wi-fi. I think I simply need to add lines, not to edit them

ok, you need to manage the information very good, you need define the package size to download, you need a webservices that allow to you to manage the information one by one, for example you need design packages no more than 500kb size to download, when this package is downloaded you can show something in your mobile and continue downloading the next package in background.
500kb is only an example you need to test what is the maximum data size to download and create packages like that in your web services

Related

Android - Get the URL of a file being downloaded

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.

Design of mobile app and server dealing with different size of photos

I don't know this title is clearly reflect the question content. Please help rephrase if you think it is confusing. Thanks!
This is a generic question about some common architecture. I am working on a Android app that can take and share photo just like Instagram. And I have a backend web service powered by Django.
The issue I am facing is, in the app, I will need to show different resolution of image (for example, thumbnails for profile image, mid-resolution for previews, and full resolution for expanded image views.) I want to ask a common pattern about how to make this happen.
I have two proposals on doing this task, and not sure which way I should go:
1.When user upload photos from the mobile app, I can compress it locally and send 3 different sizes (low res thumbnails, mid res, and high res). So server side can store them and return them back in different cases. The Con of this approach that I can think about is it will drain more user's data usage because now user will need to send multiple images. It may also cause uploading take more time and higher impact in user experience.
2.When user upload photos from the mobile app, they only upload the original image. The server side logic will do the compression for each income image, and store them accordingly. The Con of this approach is server may need to carry a lot more workload. In this case, if user increases a lot, it may crash the server.
I am hoping to get some pointer on this issue, or any reference about this topic will be helpful!
Upload the full size image to the server and have the server do the heavy lifting. Create three version of the image (small medium and large) and store them on the server (or content delivery network). Create a database table to keep track of the image id for each image and its various versions.
With android you wont know how powerful the phone running your app is, never assume it can handle whatever image manipulation you need, also try and keep network I/O as low as possible.
Alan - Think of smart phones as relatively dumb terminals made for purpose of consuming content. Most of the business logic and heavy processing should me implemented on server side.
In terms of architecture, you are facing scalability problem. You cannot expand cpu/memory or storage of a device to any level you want. However you can scale your servers horizontally or vertically by adding more ram/cores/disks etc. You can put cluster on server and have a farm of servers if data increases to that level.
So its always advisable to just upload the original image without locally processing. Locally processing also drains battery besides other downside you mentioned.
Again you business logic or processing technique changes, you have to redeploy all apps. Where as on server side such deployments are very well in your control.
What i would do is a first resize in the mobile, just one, because you dont one to transfer 13Mpx picture and also you dont want in your server a picture 2 screens wide (this is the first thing instagram does). After that, upload the file, and have the server doing the rest of the stuff.
this avoid a lot of that usage
ensures that will work fine in any device (every one has different capabilities, so you cant trust them for heavy work)
You can change some decisions about settings or configurations, and all this is centralized, if you change any common behavior, you don't need all the devices to get the last version of the app.
About crashing the server, there is one first measure i would take:
Don't do any operation, like re-sizing or making copies of the image in the moment of the upload, you can choose one of this approaches:
Do it when there is a request for the file. this is, dont do it when the user sends it, but when somebody needs it.
Do it in a continuos backgorund process, like a cronjob running every minute, for instance.
or a combination of the two, there is a process in the background doing the stuff for all the pending images, but if somebody enters in the website and they need an image that is not yet generated, it is generate in that moment.

How to build a simple offline form submission app?

I'm a Webdev beginner, have been learning some Python/PHP/Javascript and want to help a friend of mine with a project.
She's conducting a large scale survey of old houses/windows, and fills in forms (similar to Google Forms). However, she doesnt always have 3G coverage on her phone, so she wants some way of uploading the data when she gets online, and she wants to be able to upload photos and attach these to the forms.
I've found a javascript-library which makes use of html5 localstorage, but I havent understood if localstorage also accepts file uploads? Also, when you have submitted one form you would need internet access to open up the form again to submit another form.
Are there libraries or projects around that would help me with some of this, so I dont have to reinvent the wheel?
This is going to be very difficult to do with a web app. Your going to have to rely on something like AJAX to send the data and if it times out store in local storage and keep retrying every few minutes, because a web app has no access to anything like checking the wifi status etc.
Also that there is a limit to the size you can use in html5 local storage:
What is the max size of localStorage values?
, this is not going to work if you want to hold onto photos.
This would require a native or minimum a hybrid app (like phonegap) to store the data on the actual device in a file or SQLite database. This way you can store what you like, have access to the status of the internet connection and even have prompts to appear on the screen (when the app is in the background) to remind her that there are still some that need to be uploaded.
It will be much more reliable and stable this way
You can create an app which stores the data (form) in the Local DB (ie SQLite) of the App.
Once she is online (mostly wifi) she can start uploading the data.

Distributing large content in Android

I have to distribute large content to be consumed by my application. The data size can be upto a few gbs. What is the best way the data can be sent out?. The solution has to be efficient and cost effective. I ve thought about giving out sd cards (bad solution, since most devices have just one slot and nobody will use it solely for the apps purpose), downloadable from the internet (nobody will download gb's worth data from the internet),package it with the app(Not possible to upload the app to the market)
Is all of the information needed from the very beginning of the app? Maybe you can incrementally download it in the background and prioritize the data. You can set it so that it only downloads on wifi as well of give an option for it.
Android market has now extended the maximum APK file size to 4GB.
I would suggest that in the use case of downloading from the internet (i.e on the phone) then you restrict it to wifi only. THere are plenty examples of this out there using connectionmanager detection.

Downloading multiple files simultaneously in Android applications

I'm writing an application for Android which let users browse a list of files and download them.
For every download, I created a thread and I download the file with an HttpURLConnection instance (by reading from the connection in a while loop).
This method works fine with one active download. But when user starts more than one, download performance degrades dramatically. Most of the time, these parallel downloads consume all the bandwidth and the users is unable to browse files (which uses another HttpUrlConnection to load the files list).
Any suggestions on refining the download system?
Thanks.
P.S.: The method that popular browsers such as Google Chrome and Firefox do seems good. Anyone knows how they work?
Alas, i don't know of a way to throttle certain connections. However, a practical approach would be to implement a queue of downloads to control the number of simultaneous downloads. In your case, you would probably want to only let 1 thing download at a time. This can be implemented a few different ways.
Here's a way to do it with Handlers and a Looper: http://mindtherobot.com/blog/159/android-guts-intro-to-loopers-and-handlers/
Edit 1:
See mice's comment. It may be smarter to have a max of 2 threads downloading at a time.
You might want to check out the DownloadManager class in the android SDK.. Its only available above or equal api level 2.3 though.
http://developer.android.com/reference/android/app/DownloadManager.html
Some tutorials you might want to see..
http://jaxenter.com/downloading-files-in-android.1-35572.html
http://www.vogella.de/blog/2011/06/14/android-downloadmanager-example/

Categories

Resources