【发布时间】:2016-07-28 14:42:20
【问题描述】:
拍照并单击“提交”按钮后,图库应用程序崩溃。这怎么可能,我该如何解决?我的应用中从未明确使用过图库。
我使用 MediaStore.ACTION_IMAGE_CAPTURE 意图来启动相机。 要将图片保存到文件系统,我使用了此处提供的代码:https://developer.android.com/training/camera/photobasics.html
顺便说一句,我使用的是带有 Android 4.1 (API 16) 的摩托罗拉 TC55
代码sn-ps:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getContext().getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
return;
}
// Continue only if the File was successfully created
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(getContext(),
"com.example.android.fileprovider",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == Activity.RESULT_OK) {
File imgFile = new File(imagePath);
if(imgFile.exists()) {
if (HttpManager.isNetworkAvailable(getContext())) {
// Send the picture to the webserver (start AsyncTask)
} else {
// Save the call to process it later
}
}
}
}
logcat 中没有可用的日志,因为我的应用程序没有崩溃。 开始操作后在 logcat 中添加的唯一行是:
07-29 08:57:13.081 31473-31473/com.test.test W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection
[ 07-29 08:57:13.081 180: 736 E/ ]
android::status_t android::QCameraStream_preview::getBufferFromSurface(): idx = 3, fd = 82, size = 462848, offset = 0
[ 07-29 08:57:13.091 180: 736 E/ ]
android::status_t android::QCameraStream_preview::getBufferFromSurface(): idx = 4, fd = 88, size = 462848, offset = 0
[ 07-29 08:57:13.091 180: 736 E/ ]
android::status_t android::QCameraStream_preview::getBufferFromSurface(): idx = 5, fd = 94, size = 462848, offset = 0
有时我会得到这个:
07-29 09:01:19.464 12604-12604/com.test.test W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection
【问题讨论】:
-
请提供日志
-
请上传日志和您创建意图和onActivityResult方法的代码片段。
-
添加了代码 sn-ps
-
您需要添加崩溃日志。
-
好吧老兄..没有日志数据我们如何检查..问题出在哪里或问题是什么..?您的应用程序没有崩溃,没关系.. 但这并不意味着没有日志数据。重新启动您的工作室或 Eclipse 和模拟器并再次检查
标签: android android-intent android-camera