问题
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" :)
回答1:
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.
回答2:
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 !
来源:https://stackoverflow.com/questions/17059403/limitations-of-android