Thanks for sharing, wurp! Having to work like that is incredibly messy
though, and not having a Nexus One to test on I would not want to
depend on complex code like that even if it works. I hope someone can
shed more light on what is going on here and either fix the bug
(Google?) or explain what exactly are the minimum steps to finally get
the camera working reliably. The camera has been the most troublesome
and time-wasting part for me since the beginning of Android in 2008.
Since apparently even Google's sample code now fails here on their
Nexus One I think it is the Google Android developers who need to
chime in here, assuming that the problem is reproducible.

Perhaps the problem is related to what was recently discussed in the
thread

http://groups.google.com/group/android-developers/browse_thread/thread/792707bd366d4732/

I increasingly receive startPreview related crash reports for users of
Android 2.1-update1 (HKDKC100 Odroid by Hardkernel, and Motorola
Droid; no crash reports at all for Android 2.1) while my camera app
works fine on the emulator for 2.1-update1 and also runs fine on my
good old ADP1. Under such conditions I cannot properly support users
of my app who run into these problems.

Thanks

The vOICe for Android
http://www.seeingwithsound.com/android.htm

On Apr 27, 5:12 am, wurp <[email protected]> wrote:
> 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 
> 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

Reply via email to