Android - "Fail to Connect to Camera Service" -- How to Clear / Reset? - android

I'm experimenting with the Camera class. During experimentation on my Samsung Galaxy Note phone (not emulator) to open the camera im getting the error Fail to connect to camera service. I'm aware this was caused by my app not previously releasing the camera object.
I've tried stopping the debugging session and removing my app from the Application Manager but still the Camera.open(myCamId) refuses to return back a valid camera object. And for the record this worked fine the first go around.
I'm confident i can get things moving again with a phone restart but is there a quicker way to release the previously opened camera object? And no i cant simply release the camera object at this stage before re-opening bc the Camera.open is not returning ANY camera object to release.
Thanks for the tip.

If you have root access, you can kill the mediaserver process. It will restart automatically, but most likely the camera will now get connected.

No, as far as I know you have to reboot your phone.

Related

Android fingerprint sensor cancel error if grabbed by another app

I'm using FingerprintManager in my app and usually all works fine.
The main issue I have is that customers sometimes complain that the fingerprint operation is sometimes cancelled, what I can see in the logs as error 5 (Fingerprint operation canceled).
Now, I know that other apps not developed good can hold the sensor if they do not release it on inPause or similar, so even lockscreen can't use the sensor.
Is there a way to get around this issue and force the sensor to start working with my app again?
Thanks
I faced the same issue, there is an issue raised around this with Android.
https://code.google.com/p/android/issues/detail?id=208512
Here is how I am handling it in my code.
if (errMsgId != FINGERPRINT_ERROR_CANCELED) {
// As you see below that error code happens when device is locked.
}

Android studio doesn't catch breakpoint after switching to other apps

I have a problem debugging the app in Android Studio 1.4.
A typical debug aspect is when, debugging on a physical device, I purposedly switch to other
apps and then I come back to my app to check if the current Activity has some
"null" variables that prevent activity from properly recharging.
I usually set some breakpoint at the beginning of the (onResume) method.
The problem is: when I run the app the first time, the breakpoint is normally taken.
When I switch to other apps and then return to the debugging app,
Android Studio doesn't catch the breakpoint, so I cannot debug what's wrong.
The same thing seemed to work properly in Eclipse.
Do you have any idea how to solve this? Thanks.
if your process is killed then the debugger is no longer attached.
You can attach a new debugger at any point
do this just after you finish using the last app and before you open your app
It will give you a list of processes and you have to select which process to attach the debugger to.
Usually the process name includes a prefix of your package name.
https://blog.pivotal.io/labs/labs/fast-android-debugging-with-intellij

How to prevent Android App from crashing abruptly

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.

Android: how to tell when the camera is activated

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.

When did Application restart?

Sometimes I see my app in DDMS restart.As I see it's process id changed.(I'm not sure that,because I don't write log for application oncreate.)
That behaviour ofen happened when I mount SDCard to share USB mode.I'd like to see what happend after mount in my application.So I debug my App,but unfortunately.When mount to share USB mode,application's process id changed and debug been auto stopped.
Why?What happened?What's the strategy for android handle application restart?
And there is another question.Why does sometimes an activity occur an error,thrown an exception dialog,and restart it.Sometimes the android platform just kill the activity and exit.
Maybe it's not a very useful question for develop.But I'm really missing,I want to know the answer.Please help me,friends.Thank you very much.
I used to get into similar cases like yours, what I did to handle and detect is like:
1. Check Device: sometimes devices mal-functioning really cause problems, a bad USB cable will really do restart Android/application.
2. Collect Log: after application restarts, just collect the log from system/event/radio/dumpstate... remember the time when app started to restart then check in log files to look for the causes.
Well, that's my experiences and it works, not in all situations but most of the time.

Categories

Resources