尝试在不同设备上拍照时应用程序崩溃 - Android
我的应用程序允许用户使用相机拍照。
我已经在多种设备(Nexus S、Nexus One、HTC Magic 和 Galaxy S)上进行了测试。该应用程序在前 3 款手机上运行良好,但在 Galaxy 上崩溃了。
这是我写的代码 -
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "121.jpg");
values.put(MediaStore.Images.Media.DESCRIPTION,"Image capture by camera");
imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(cameraIntent, 2);
这是 OnActivityResult 函数 -
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
else if (requestCode == 2)
{
sun=getRealPathFromURI(imageUri);
File f = new File(sun);
thePic.setImageBitmap(decodeFile(f));
}
}
}
resultCode 返回为 0(不是 RESULT_OK),然后应用程序崩溃。
谢谢!
My app has enables the users to take a photo using the camera.
I've tested it on several devices(Nexus S,Nexus One, HTC Magic and Galaxy S). The app worked fine on the first 3 phones, but crashed with the Galaxy.
This is the code I wrote -
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "121.jpg");
values.put(MediaStore.Images.Media.DESCRIPTION,"Image capture by camera");
imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(cameraIntent, 2);
And this is the OnActivityResult function -
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
else if (requestCode == 2)
{
sun=getRealPathFromURI(imageUri);
File f = new File(sun);
thePic.setImageBitmap(decodeFile(f));
}
}
}
The resultCode is returned as 0(not RESULT_OK), and then the app crahses.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论