2

I need to build an app that takes a camera image and uploads it to the web where some processing is to be done and a true/false is returned. I encounter some questions in this respect on which a clarification would be well appreciated.

1.) Is there any way my app can know image being captured by the android camera? What I understood from here (Android: BroadcastReceiver intent to Detect Camera Photo Taken?) is that we can know whenever a picture has been added to the phone,be it via Bluetooth or through a camera capture or otherwise. Any way that is just fine. The question is doesn't that need my app to run in the background so as to detect change in media store? If that is the case I can make my app to open the camera and then capture the image which will be more efficient in terms of power.

2.) Is there any limitation to the size of the image that can be send from an android phone to the web? Considering that the RAM of the android phones is less etc.(I am asking this b'coz I encountered a similar issue in another app where I needed to do things like increasing the brightness,contrast etc..The app crashed when the image size was greater than 10MB).

"I don't want to reinvent the wheel and waste my time" :)

Community
  • 1
  • 1
Sreekanth Karumanaghat
  • 3,383
  • 6
  • 44
  • 72

2 Answers2

4

1.) There is effectively this kind of mechanism in Android development which is bulked in and already done for you :) This mechanism is called Intent and you just have to declare it on your application, the system take care of calling your registered component for you

2.) No limitation here, but you have to be carefull to send it with a background thread or a service (to not block the UI thread) and handle connection timeout etc

And yeah efficient works doesn't need to reinvent the wheel !

Plumillon Forge
  • 1,659
  • 1
  • 16
  • 31
  • Just to add to this, do not mistake 'a async thread' for AsyncTask. AsyncTasks are NOT the place for any HTTP stuff, and certainly not long running ones. – Stefan de Bruijn Jun 12 '13 at 07:23
  • 1
    Yeah you're absolutely right, I wasn't refering to AsyncTask, I'll rephrase to avoid misunderstanding :) – Plumillon Forge Jun 12 '13 at 07:27
  • Are you sure about the image sending? Why I am asking again is because, I need to open the image to convert into bytes and then only I can send them,It is not possible to open/read the images in android phones when they are large,typically greater than 10MB,the app crashes(Unless we use NDK or something which I havent been able to do till now). What do you think? – Sreekanth Karumanaghat Jun 12 '13 at 07:33
  • To avoid OOM you will have to send your large file with a limited reading byte and a while loop, you can find an example here : http://stackoverflow.com/questions/9745514/sending-file-1mb-using-http-post (remember to flush) – Plumillon Forge Jun 12 '13 at 07:43
  • But for that the image has to be loaded into the memory right. I mean I am talking about.File = new File() something, the code will crash here I suppose. – Sreekanth Karumanaghat Jun 12 '13 at 07:49
  • 1
    There are various ways to avoid opening / keeping large file in memory like the HttpURLConnection.setChunkedStreamingMode(int) for instance : http://developer.android.com/reference/java/net/HttpURLConnection.html#setChunkedStreamingMode(int) – Plumillon Forge Jun 12 '13 at 07:58
  • @PlumillonForge Is there any way I can test this without actually writing and implementing the server side code? – Sreekanth Karumanaghat Jun 12 '13 at 09:40
2

To try and answer your questions;

1) Registering a BroadcastReceiver doesn't really translate into having your app running in the background 24/7. It's rather like you register your app in the system, which will boot and notify it when needed. You don't have to be afraid of using up battery by having these Receivers, as long as you don't do battery-intensive things on very regular broadcasts.

2) There is not really any limit, although it should make sense to you that sending 100mb, possibly over someone's 3G connection, wouldn't make anyone happy. If a previous app of you crashed while trying to send 10MB, you probably did it the wrong way like making it a base64 string. I'm not sure to what kind of server you're going to upload it, but you want to find some code sample that buffers the image up to the server in small chunks. Also keep in mind that on a phone, you can never be sure of a stable connection.

Stefan de Bruijn
  • 6,289
  • 2
  • 23
  • 31
  • @Stefan.. 1)For the broadcast Reciever to work, doesn't the app need to be in running state or minimized state? 2)Previous app crashed because I tried to do the image processing inside the phone, that required me to read the image data of an image that has a size >10MB. I hope you get what I meant. – Sreekanth Karumanaghat Jun 12 '13 at 07:09
  • 1
    Nop once the system is aware of your Receiver, it handles the call for you. You don't have to run your application un background (but you can too if you need to) – Plumillon Forge Jun 12 '13 at 07:12
  • @Plumillon.. so only when the receiver receives a notification (In this case a change in the media store),the app needs to be opened I suppose. – Sreekanth Karumanaghat Jun 12 '13 at 07:14
  • 1
    @SreekanthKarumanaghat Like i said, you should compare it more like this: the system keeps a list of all registered apps for every broadcast, and simply starts those app's Receivers and notifies them. They're not using battery until called and starting to do something. – Stefan de Bruijn Jun 12 '13 at 07:15
  • 1
    Yeah and this is done by Android, which will fire your implemented method where you do all what you want – Plumillon Forge Jun 12 '13 at 07:16
  • That is a brilliant feature of android I must admit. – Sreekanth Karumanaghat Jun 12 '13 at 07:29
  • @StefandeBruijn Are you sure about the image sending? Why I am asking again is because, I need to open the image to convert into bytes and then only I can send them,It is not possible to open/read the images in android phones when they are large,typically greater than 10MB,the app crashes(Unless we use NDK or something which I havent been able to do till now). What do you think? – Sreekanth Karumanaghat Jun 12 '13 at 07:32
  • It should work fine if you find a good example :) Sending over images and even bigger files is something that enough apps do ;) – Stefan de Bruijn Jun 12 '13 at 07:52