On low memory device I've got a problem after calling camera intent. When activity result should be received Android restart the whole app.
Have anybody faced same problem? Is there any solution?
I faced the same issue a while ago:
Android system stops application when launching Media Intent
Apparently there is no solution, so you have to make sure that you save and restore the application state.
Well i think, the problem could be: Image byte array is too big such that it touches the limit and android restarts the application so following is what will i do:
Calling the intent with some parameter telling to downsample the bytes it gonna send back.
OR
Implement your camera using surfaceview and then when user takes some picture, save it temporarily on sdcard and return only the path... then get the path in onActivityResult and use the picture.
Hope it helps.
Related
I know this is a very broad question on how to prevent an Android app from crashing. I understand there could be many reason behind the app crashing.
Primarly my app crashed because of 2 main reasons :-
1) Out of memory while taking pictures and storing byte array in memory. I also uses bitmap to redraw the image captured.
2) Camera issues. App has a feature of autofocusing on touch events and while actually taking the pictures. These autofocus often crashes into each other. I have handled it using cancelling any existing autofocus code and discarding any further on touch events using flags once the picture is being captured. But still some time app crashes due to unknow reason.
There may be more reason behind app crashes. So my question is
1) Is there a way I can identify that app has crashed and handle that event so that instead of just showing the messsage ""UnForunately App has stopped working. Force Close." I can give a better user friendly message to user and stop the app programatically.
2) If out of memory every happens, is there a way I can identify that my App is running low on allocated memory and I can handle the scenario. OnLowMemory will give the low memory status of entire device, not just my application. I use lot of cache to store the images & heap for bitmap.
3) If the camera ever crashes (because of any reason), is there a way I can handle the scenario.
Thanks in advance.
Gagan
The android application usually crashes if there is a run time error.
You can locate and avoid the crash,using android monitor and write your code in try catch block.
Example:
try{
"your code which might give error"
}
catch(Exception e)
{
Log.e("TAG or Some text",e.toString());
finish(); //or some methods you want to do if the code inside try block fails;
}
Now, the app wont crash and you can locate the error in android monitor by searching for TAG error.
Let's say I have an application with an activity which list a bunch of files. When the user touch one of this files an ACTION_VIEW intent with proper mimeType and stuff is triggered so Android will prompt the user to choose one of the video players installed in the system (or the one that's defaulted).
I'm wondering if there is a way of telling if the playback of the file itself succeded or not. Because if I detect there was an error I can recomend the user other players available on Google Play.
¿Does the default Android Video Player responds the intent with some data? ¿Is there some generalized, common or standard way to get this information?
Any data on the subject is appreciated.
Thanks in advance.
I'm wondering if there is a way of telling if the playback of the file itself succeded or not.
You can tell if there was any eligible activity for the ACTION_VIEW Intent, either by catching ActivityNotFoundException on your startActivity() call, or by calling queryIntentActivities() ahead of time and checking for an empty list.
Once control passes to the third-party activity, that activity is like Las Vegas: what happens in that activity stays in that activity. You have no way of knowing anything about what went on, in terms of "success" or "failure" or anything else.
At the moment my app has a service running which is fired every hour. This pulls any photos thats have been taken since last time it was open and uploads then to the server. This is done using the system content provider
Now what I want to do is send an intent to open the camera app, I am doing this like so...
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
What I would like to happen is when the focus comes back to my app (after the user has taken a picture), I can open the service and that takes care of the photo.
However it seems like the photo is never added to the content provider. The service opens it and the cursos has a count of 0. Is there anything i can do so the system adds the photo to the content provider or do I need to handle this myself?
Edit
So I figure there no intents I can use to get it to save to the system. So it would seem my options are either
contentResolver.insert()
or
MediaStore.Images.Mediea.insertImage()
What is the difference between these 2 methods?
Edit
So I am starting to think google are clueless with there implementation of this feature. Take this link
http://developer.android.com/guide/topics/media/camera.html#intent-receive
You pass in the Uri and when it returns to your app it gives you the uri you gave it. If you did not specify a uri it doesn't return one. What is the point in that? Why would I want data I already have? Surely it would make sense the other way around. Or even just giving you basic data you need such as name, path, mimetype. Would that be too difficult?
Notify MediaScanner, when the scan is complete your photo will be added to the system database.
I'm writing an Android app that the user can run in the background to detect when the camera is turned on(by the user, or by other apps). This should also detect even in the scenario where other apps (like facebook, instagram) do not use the default android camera app.
I've been searching but haven't seen any broadcasts that are sent whenever the camera is activated. So far, I've seen that there's Camera.open() that throws a RuntimeException if the camera is already in use by another app. So one way is to keep polling Camera.open(), but it's really expensive. Is there a better alternative?
Thanks
Edit: Sorry i didn't mention it clearly but what I want to do is to create some kind of camera usage log: what time it was turned on/off, how long was the duration, etc..
What happens internally is Camera API talks to CameraService and CameraService has mBusy variable which tracks whether camera is busy or not. And there is no API to get this mBusy flag out of service (without calling open())
I may be wrong, because I just glanced over it.
You can download Android source code (http://source.android.com/) and take a closer look yourself.
Files which could be interesting for you are:
\frameworks\base\services\camera\libcameraservice\CameraService.cpp
\frameworks\base\libs\camera\Camera.cpp
\frameworks\base\core\java\android\hardware\Camera.java
\frameworks\base\core\jni\android_hardware_Camera.cpp
One other idea. Try to look in the logs. In the case, if logs aren't turned off for Camera services/API, you can parse the logs to check when the camera was turned on or off. However, it may not work in OS 4.1, because Google limited reading of system logs.
I am trying to find out if droid stores the last time the MediaScanner had been run. Anyone know a way to check or if android stores that data?
According to the documentation there is no way to find the last time the MediaScanner ran. However, you can force a scan by using the scanFile() function:
http://developer.android.com/reference/android/media/MediaScannerConnection.html
I don't know if android saves the time log for the media scanner activity, however, you would know if the media scanner is already finished scanning by handling the ACTION_MEDIA_SCANNER_FINISHED intent.