“致命异常:GLThread 11”在 Android 上 froyo 2.2
我用谷歌搜索了很多,发现了一些关于堆栈溢出的线程,但没有帮助。我试图通过调用 Intent 来使用 Android 的内置摄像头。这适用于 2.1,但在 2.2 上我得到“致命异常:GLThread 11”异常。
我读了这个话题 Android 2.2 中的相机崩溃
以及 Google 线程 http://code.google.com/p/android/issues/ detail?id=7909
String fileName = Environment.getExternalStorageDirectory().getAbsolutePath() + "temp-" + System.currentTimeMillis() + ".jpg";
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
values.put(MediaStore.Images.Media.DESCRIPTION,"Image capture by camera");
imageUri = ctx.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_OUTPUT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
//http://marakana.com/forums/android/examples/39.html
ctx.startActivityForResult(intent, REQUEST_CODE);
这是我用来调用相机的代码。我想很简单。但是当我拍照并点击“保存”/“接受”按钮时,应用程序在 Android 2.2 中崩溃。在我看来,这是标准的代码和功能。我如何使用内置摄像头。我已经尝试了几件事。
I've googled a lot and found a few threads on stack overflow but it didnt help out. Im trying to use the built-in camera of Android by invoking an Intent. This works on 2.1 but on 2.2 i get the "FATAL EXCEPTION: GLThread 11" exception.
I read this topic
Camera crashes in Android 2.2
And the google thread
http://code.google.com/p/android/issues/detail?id=7909
String fileName = Environment.getExternalStorageDirectory().getAbsolutePath() + "temp-" + System.currentTimeMillis() + ".jpg";
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
values.put(MediaStore.Images.Media.DESCRIPTION,"Image capture by camera");
imageUri = ctx.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_OUTPUT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
//http://marakana.com/forums/android/examples/39.html
ctx.startActivityForResult(intent, REQUEST_CODE);
This is the code that i use to invoke the camera. Straightforward i guess. But when i take the picture and hit the 'save'/'accept' button the app crashes in Android 2.2. In my opinion it's standard code and functionality. How can i use the built-in camera. I've tried several things.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让我自己回答:)我设法让它工作。我还在探索 Android。首先,上面的代码永远不会工作。尽管如此,使用相机并对其进行测试仍然是一项艰巨的工作。我无法在 2.2 的模拟器中获得意图,但对于 2.1,它可以工作。但该代码适用于设备上的 2.2 和 2.1。我发现的另一个奇怪的事情是,当您将调试器附加到设备时,不可能使用 MediaStore.Images.Media.EXTERNAL_CONTENT_URI。它会抛出外部存储不存在的错误。它与 USB 连接有关。无论如何,用于意图相机的代码:
非常标准,我添加了 try catch 以避免当我将调试器附加到我的设备时应用程序崩溃。如果您为 MediaStore.EXTRA_OUTPUT 传递 null,相机将显示一条消息,指出无法找到 sdcard。这比崩溃更好。
拍照后,相机将返回到您当前的活动,您可以使用将存储在 imageUri 变量中的图像。
在 2.2 的模拟器中,当我尝试使用相机时,仍然会抛出错误“FATAL EXCEPTION: GLThread 11”,这很烦人。有人有办法让它在模拟器上运行吗?
Let me answer it myself:) I managed to get it working. Im still discovering Android. First of all the code above will never work. Nonetheless its still a hell of a job to work with camera ... and test it. I cant get the intent working in the emulator for 2.2, for 2.1 it works. But the code works for 2.2 and 2.1 on the device. Another weird thing that i discovered is that when you attach the debugger to your device its not possible to use MediaStore.Images.Media.EXTERNAL_CONTENT_URI. It throws an error that the external storage doesnt exist. It has to do with the USB connection. Anyway, the code used to intent the camera:
Pretty standard, i added the try catch to avoid that the app crashed when i attach a debugger to my device. If you pass null for MediaStore.EXTRA_OUTPUT the camera will show a message that the sdcard could not be found. Which is better then crashing.
After you take the picture the camera will return to your current activity and you can use the image which will be stored in the imageUri variable.
In the emulator for 2.2 the error “FATAL EXCEPTION: GLThread 11” is still thrown when i try to use the camera, which is annoying. Does anyone has a solution to get it working on the emulator?