I did have this same problem. The issue is that the Camera.open
method bombs out.
I created a camera wrapper class that does a bunch of initialization
to ensure that open works, then takePicture works, etc. I found the
initialization code by looking through the Camera source code for
Google's main Camera app.
I think the code you need is:
private synchronized void preOpen(Context context) {
mPreferences =
PreferenceManager.getDefaultSharedPreferences(context);
upgradePreferences(mPreferences);
}
public static final String KEY_VERSION = "pref_version_key";
public static final String KEY_RECORD_LOCATION =
"pref_camera_recordlocation_key";
public static final String KEY_VIDEO_DURATION =
"pref_camera_video_duration_key";
public static final String KEY_JPEG_QUALITY =
"pref_camera_jpegquality_key";
public static final int CURRENT_VERSION = 3;
private static void upgradePreferences(SharedPreferences pref) {
int version;
try {
version = pref.getInt(KEY_VERSION, 0);
} catch (Exception ex) {
version = 0;
}
logPreferences(pref);
if (version == CURRENT_VERSION) return;
SharedPreferences.Editor editor = pref.edit();
if (version == 0) {
// For old version, change 1 to 10 for video duration
preference.
if (pref.getString(KEY_VIDEO_DURATION, "1").equals("1")) {
editor.putString(KEY_VIDEO_DURATION, "10");
}
version = 1;
}
if (version == 1) {
// Change jpeg quality {65,75,85} to
{normal,fine,superfine}
String quality = pref.getString(KEY_JPEG_QUALITY, "85");
if (quality.equals("65")) {
quality = "normal";
} else if (quality.equals("75")) {
quality = "fine";
} else {
quality = "superfine";
}
editor.putString(KEY_JPEG_QUALITY, quality);
version = 2;
}
if (version == 2) {
editor.putString(KEY_RECORD_LOCATION,
pref.getBoolean(KEY_RECORD_LOCATION, false)
? "on"
: "off");
version = 3;
}
editor.putInt(KEY_VERSION, CURRENT_VERSION);
editor.commit();
}
I can't imagine a reason this would be required, but after I added it,
Camera.open worked. Strangely, later I commented out the call to
upgradePreferences and it still worked... I don't know if that's
because the critical thing is just acquiring the preferences, or
somehow one time initialization is enough.
I noticed also that rebooting my phone and making the Camera.open be
the very first thing I did also worked (without the preOpen call).
None of this behavior makes sense to me; I'm just reporting what I
saw, and what has continued to work for me.
BTW, you also have to startPreview before you can takePicture.
Bobby
On Apr 25, 10:21 am, Scott Sheppard <[email protected]> wrote:
> I am running the android-7 ApiDemo sample project on a Nexus One
> device. I am interested specifically in the Graphics/CameraPreview
> sample code. The project works fine, but when I select Camera the
> device displays a Force Quit message. I am not receiving any error
> information in the debugger.
>
> The CameraPreview code works fine in the emulator.
>
> Anyone else had this problem?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group
> athttp://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en