2016-07-28 58 views
0

拍完照片并点击“提交”按钮后,画廊应用程序崩溃。这怎么可能,我该如何解决它?该画廊从未在我的应用程序中明确使用。画廊照相后坠毁(意图)

我用MediaStore.ACTION_IMAGE_CAPTURE意图启动相机。 要将图片保存到我这里使用的提供的代码文件系统:https://developer.android.com/training/camera/photobasics.html

顺便说一下我使用的是摩托罗拉TC55采用Android 4.1(API 16)

代码片段:

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 
+0

请提供日志,请 – ddb

+0

上传日志和snipet代码,您在此创建intent和onActivityResult方法。 –

+0

添加了代码片段 – wm377

回答

0

我固定它通过使用代码示例项目:android developer site

我认为问题是,安卓4.1是没有完全和FileProvider兼容。因此,在将图片保存在文件中时(图库应用程序中)出现故障。示例代码不使用它(还)。

0

这样的问题时,在前面的页面(或类)输入连接尚未关闭。检查你是否关闭了前一课的输入连接(通过给connection.close())。

当您离开活动并保持HTTP连接处于打开状态时,会出现此问题。

+0

我关闭了(.disconnect())HttpURLConnection,但它并没有解决问题不幸 – wm377