I am trying to take a photo but it hangs when takePicture is called. No exception is generated. My code runs in an AsyncTask which is launced from a service. No activity is used and none MUST be used. I'm running this on Android 2.3.6. I can wait minutes and the onPictureTaken is never called.
Code:
import android.annotation.SuppressLint;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.os.AsyncTask;
import android.os.Build;
public class CameraAsyncTask extends AsyncTask<Void, Void, Boolean> implements Camera.PictureCallback
{
private Camera camera;
@Override
protected Boolean doInBackground(Void... params)
{
this.camera = Camera.open();
this.camera.takePicture(null, null, (PictureCallback) this);
this.camera.release();
}
@Override
protected void onPostExecute(Boolean succeeded)
{
}
public void onPictureTaken(byte[] data, Camera camera)
{
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
</manifest>